Backend/공통

AWS 에 nginx 설치

Dean83 2024. 10. 25. 16:22
  • 터미널에서 다음의 명령어 입력
    • sudo apt install nginx
    • cd /etc/nginx/sites-available/
    • sudo nano 원하는이름
      • 설정파일명이 된다
server {
       listen 443 ssl;
       server_name 서버이름;

       ssl_certificate /path/to/certificate.crt;
       ssl_certificate_key /path/to/private.key;
       ssl_protocols TLSv1.2 TLSv1.3;
       ssl_ciphers HIGH:!aNULL:!MD5;

        location / {
                proxy_pass http://localhost:개발에사용한_포트번호; 혹은 서버 주소
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
        }
}
  • X-Real-IP : 백앤드 서버 입장에서 들어온 요청은 모두 nginx 정보이므로, 실제 클라이언트의 ip를 알기 위해 사용
  • proxy_pass 는 요청을 http://localhost:포트번호 로 리다이렉트 한다는 의미
  • 저장후 터미널에서, 
    • cd /etc/nginx/sites-enabled/
    • sudo rm default
    • sudo ln -s /etc/nginx/sites-available/설정파일명
      • 위에서 저장한 파일명
    • sudo systemctl restart nginx