OPS

[Nginx] Nginx와 AWS ELB 연동해보기

찻잔속청개구리 2024. 5. 26. 14:27
반응형

 

1. 기존 /etc/nginx/sites-available/default 파일 다른 이름으로 변경

root@ip-10-0-9-213:/etc/nginx/sites-available# ll
total 16
drwxr-xr-x 2 root root 4096 Mar 12 06:10 ./
drwxr-xr-x 8 root root 4096 Mar 12 05:57 ../
-rw-r--r-- 1 root root 1850 Mar 12 06:10 default
-rw-r--r-- 1 root root 1549 Mar 12 04:51 default-backup

 

2. location / 에 proxy_pass 추가

proxy_pass      http://{NLB-DNS}:포트;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Hsot $http_host;

 

2-1. 구체적 예시

  1 server {
  2         listen 80 default_server;
  3         listen [::]:80 default_server;
  4 
 20 
 21         root /var/www/html;
 22 
 23         # Add index.php to the list if you are using PHP
 24         index index.html index.htm index.nginx-debian.html;
 25 
 26         server_name localhost;
 27 
 28         location / {
 29                 proxy_pass      http://xxxxx-nlb-xxxxxxx.elb.ap-northeast-2.amazonaws.com:8080;
 30                 proxy_set_header X-Real-IP $remote_addr;
 31                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 32                 proxy_set_header Hsot $http_host;
 33                 # First attempt to serve request as file, then
 34                 # as directory, then fall back to displaying a 404.
 35                 try_files $uri $uri/ =404;
 36         }
 37 
 57 }
 58

 

3. 접근 확인

반응형