반응형

 

 

1. 프록시 서버란?

중계 서버이다. 나가거나 들어올때 거치는 중간 통로. 프록시 종류에는 두 가지가 있는데

1) 순방향(Forward) 프록시 : 내부망에서 외부망으로 나갈 때 거치는 프록시

프록시를 거쳐 나가기 때문에 인바운드/아웃바운드 정책을 제어할 수 있고

한번 다녀왔던 목적지면 캐쉬가 남아있어 빠른 통신이 가능하다.

 

2) 역방향(Reverse) 프록시 : 외부망에서 내부망으로 들어올 때 거치는 프록시

중간단계의 프록시를 거쳐 내부로 들어오기 때문에 내부에 뭐가 있는지 알 수 없다.

또한 로드밸런싱 을 통해서 들어오는 부하량에 따라 분배할 수 있다.

 

2. 설치방법

https://nginx.org/en/download.html

 

nginx: download

 

nginx.org

 

 

◀ Stable version 으로 다운로드

 

 

 

conf 폴더 안에 nginx.conf 설정 파일을 열어본다

 

 

기본적으로 설정되어 있는 내용이다. 절반 이상이 주석처리가 되어있다.

예시로 어떤 기능을 어떻게 사용하면 되는지 되어있다.

#user  nobody; 
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 

내가 해야할건 외부에서 들어올 때 주소를 뭐라고 해야 들어올 수 있고 

https 프로토콜을 사용해야 하고, mobile.maaani.com/api 경로로 들어오는 내용들은 

reverse proxy 로 내부 서버로 리다이렉트 해주고.. 정도 이다.

더 세분화된 옵션들이 있지만 일단 제일 간단하게 설정해보자

 

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    # 서버
    server {

        # SSL
        listen       443 ssl; # 443 (https) ssl 을 적용하겠다
        server_name  mobile.maaani.com; # 이 주소로 서버로 접근할 수 있다
        ssl_certificate      ./etc/ssl/mobile.maaani.com.crt; #인증서
        ssl_certificate_key  ./etc/ssl/mobile.maaani.com.key; #인증서
	ssl_client_certificate ./etc/ssl/Chain_RootCA_Bundle.crt; #인증서
        ssl_session_timeout 10m; #타임아웃
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 

	charset utf-8;

		# https://mobile.maaani.com 으로 들어오면 index.html 을 표시
        location / {
             root   html;
             index  index.html;

             access_log      logs/access.log;
             error_log       logs/error_log;
         }

		# https://mobile.maaani.com/api 로 들어오면 proxy (localhost:3300)
        location /api {
             access_log      logs/access.log;
             error_log       logs/error_log;

             proxy_pass http://localhost:3300;
         }

		# error page
        error_page 500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 

한번 외부에서 저 주소로 접속이 되나 테스트해보자

https://mobile.maaani.com

 

 

https://mobile.maaani.com/api/board

 

config 에서 /api 로 들어올경우 localhost:3300 으로 proxy 정상적으로 적용이 되었다

 

3. SSL 은 어떻게 구했어

으응.. 유료로 구매했다

구매하니까 3개의 인증서가 들어있었다

 

물론 무료로 SSL 인증서 만들기도 할 수 있다 (openssl)

 

 

반응형
도움이 되셨다면 공감 클릭 부탁드리며
출처만 남겨주시면 글 내용은 마음껏 퍼가셔도 좋습니다 :)