OpenSource

Nginx proxy 설정

아르비스 2019. 2. 27. 13:21

NGINX를 이용하여 Forward proxy를 구성하려 함.


Proxy 서버의 2종류


Image result for reverse proxy

1) Forward Proxy

Proxy Server에서 In/Out bound 패킷에 대한 보안 정책(Content filtering 등)을 적용할 수 있다


2) Reverse Proxy

외부 사용자는 실제 내부망에 있는 서버의 존재를 모른다. 모든 접속은 Reverse Proxy 서버에게 들어오며, Reverse Proxy는 요청에 맵핑되는 내부 서버의 정보를 알고 요청을 넘겨준다. 따라서 내부 서버의 정보를 외부로부터 숨길 수 있다.


지금은 방화벽 문제로, Forward Proxy를 Nginx를 이용하여 구성하려고함.


1. 설치 

Download URL : http://nginx.org/en/download.html


설치하려는 OS 버전에 맞는 내용을 선택 다운 받으면 됨.

 windows의 경우 별도의 설치 없이, exe 만 실행하면 됨.

1) 실행

실행 : nginx.exe   (실행시키면 아무런 변화 없음)

2) 확인방법

http://localhost/ 실행

Image result for welcome to nginx

3) 종료

실행 : nginx.exe -s stop 

(/logs/nginx.pid 기준으로 종료시켜서, 중복 실행할 경우 문제 발생함)


2. 설정 (Config)

Nginx가 설치가 완료되었다면, /conf/nginx.conf 로 설정파일 존재.


1) (일반적인) Revers Proxy 설정

 #

# The default server

#

server {

 listen 80;

location / {

 proxy_pass http://127.0.0.1:3000/proxy_1;

 }

 location /test {

 proxy_pass http://127.0.0.1:3000/proxy_2;

 }

 error_page 404 /404.html;

 location = /40x.html {

 }

error_page 500 502 503 504 /50x.html;

 location = /50x.html {

 }

}

http://Proxy서버IP:80 으로 들어오면 location / 에 해당된다. http://Proxy서버IP:80/test 로 요청이 들어올 경우 location /test에 맵핑된다.proxy_pass는 들어온 요청을 어디로 포워딩 해주는지 지정


2) Forward Proxy 설정

server {

        listen 8080;

server_name docker.com;

return 301 https://download.docker.com$request_uri;

    }

특정 Port 8080 으로 접속시, docker site로 forward


3) Proxy Server any

 server {

    listen       8888;


    location / {

        resolver 8.8.8.8; # may or may not be necessary.

        proxy_pass http://$http_host$uri$is_args$args;

    }

}