Nginx

Nginx란?


Nginx 주요 기능

실습 코드

default.conf :

upstream blue {
        server 172.31.35.149:8080;
}
upstream green {
        server 172.31.35.149:8081;
}
# blue일 경우 8080 green일 경우 8081으로 통신하도록 한다.

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    include /etc/nginx/conf.d/service-env.inc;
    # inc파일에서 변수를 가져와 blue인지 green인지 셋팅한다.

    #access_log  /var/log/nginx/host.access.log  main;
    location / {
        proxy_pass http://$service_url;

        proxy_set_header X-Real-IP $remote_addr;
        #백엔드 서버가 클라이언트의 실제 IP를 알 수 있도록 도와줍니다.
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #프록시를 거친 경우, 이 헤더는 모든 IP를 기록하여 트래픽의 출처를 추적할 수 있도록 합니다.
       
        proxy_set_header Host $http_host;
				# 클라이언트가 요청한 원래 Host 헤더 값을 백엔드 서버로 전달합니다.
        root   /usr/share/nginx/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   /usr/share/nginx/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;
    #}
}

service-env.inc

set $service_url blue;