프록시란 "대신" 이라는 의미를 가지고 있다. 프로토콜에 있어서 대리 응답 등에서 사용하는 개념이다.
보안상의 문제로 직접 통신을 주고 받을 수 없는 사이에서 프록시를 이용하면 중계 개념이라고 볼 수 있다.
프록시 서버 : 중계 역할을 해주는 서버를 의미
프록시 서버의 종류
Forward Proxy
Forward Proxy
Revers Proxy
Revers Proxy
FATC.CLUB에는 3개의 서버가 존재한다.(1) 블로그를 담당하는 fatc.club,(2) 블로그 내용을 구현하여 보여주는 etc.fatc.club 그리고(3) IP 제공 서비스를 수행하는 ip.fatc.club 그리고 모든 요청은 1개의 Proxy 서버를 통해 들어온다. 그러면 어떻게 (1)~(3)을 구분해야 할까. 일반적으로 도메인을 보고 어떤 서버로 해당 요청을 밀어낼지 결정한다. 출처: https://jcdgods.tistory.com/322
이처럼 다수의 서버를 Proxy 서버 하단부에 위치시켜 두고, 특정 조건(위에서는 도메인)에 맞는 요청을 적절한 서버에게 전달해주는 역할을 수행하는 것이 Reverse Proxy이다.
# 필수 설치
sudo yum update
sudo yum install gcc
sudo yum install cmake
sudo yum install patch
sudo yum install pcre-devel
sudo yum install zlib-devel
# Nginx 설치
wget http://nginx.org/download/nginx-1.17.0.tar.gz
tar -xzvf nginx-1.17.0.tar.gz
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
cd nginx-1.17.0/
patch -p1 < ../ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch
./configure --add-module=../ngx_http_proxy_connect_module
sudo make및 make install
# 생성 확인
/usr/local/nginx
# 명령어 등록
cd /usr/bin
sudo ln -s /usr/local/nginx/sbin/nginx nginx
nginx.serveice 수정
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
nginx.conf 파일 추가
# vi /usr/local/nginx/conf/nginx.conf
error_log logs/error.log;
access_log logs/access.log;
http {
keepalive_timeout 65;
server {
listen 1234; # 열고싶은 포트
server_name "1.2.3.4"; # 프록시 서버의 도메인 또는 IP 주소
access_log logs/access.log;
# dns resolver used by forward proxying
resolver 8.8.8.8;
# forward proxy for CONNECT request
proxy_connect;
proxy_connect_allow 443 563;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
proxy_pass $scheme://$http_host$uri$is_args$args;
}
}
실행 명령어
# 실행 명령어
# register service
sudo systemctl enable nginx.service
# start NGINX
sudo systemctl start nginx.service
# NGINX 상태 확인
sudo systemctl status nginx.service
# or
ps aux | grep nginx
# or
netstat -tlnp
#테스트 OK 출력
sudo nginx -t
#재실행 명령어
sudo systemctl restart nginx.service
테스트
- GCP 방화벽 규칙 추가 (GCP 사용한해서 VM이 2대일 경우 진행 X)
Python 정상 접근 코드 작성
import requests
url = "원하는도메인"
proxies = { 'http': 'http://"프록시서버의 도메인이름 또는 IP주소":"설정한 포트번호"', 'https': 'http://"프록시서버의 도메인이름 또는 IP주소":"설정한 포트번호"', }
res = requests.get(url, proxies=proxies)
print res.content