[nginx] Spring boot 를 위한 Reverse Proxy 설정하기

2021. 8. 17. 16:35IT개발/Trouble Shooting

반응형

※ Reverse Proxy 란? Forward Proxy와 차이점은?

https://www.lesstif.com/system-admin/forward-proxy-reverse-proxy-21430345.html

 

실제 우리가 세팅하고자 하는 동작 흐름

1. nginx 설정

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

    include /etc/nginx/conf.d/*.conf;

}

2. api.conf 설정 (  /etc/nginx/conf.d/api.conf )

server {
    listen 80;
    server_name api.yourdomain.com;

    location / {
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Forwarded-Proto $scheme;
	proxy_set_header Host $http_host;
	proxy_set_header X-NginX-Proxy true;

	proxy_redirect off;
        proxy_pass         "http://127.0.0.1:8080";
    }
}

3. 참고로 웹서버 설정(vue 배포본이 위치할...)

server {
    listen       80;
    server_name  www.yourdomain.com;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
	try_files $uri $uri/ /index.html;
    }

    #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   /usr/share/nginx/html;
    }

}

 

반응형