[nginx] nginx를 활용해 AWS EC2에 https 적용하기 (무료 SSL 인증서 발급)

⚠ 오픈비두 서버를 on promises 방식으로 설치할 때, 80포트와 443포트를 사용하고, nginx에서도 80과 443을 사용하여 포트가 겹쳐 둘 다 작동하지 않는게 문제였다.

해결방법

  1. 오픈비두 서버 포트를 http : 8080 / https : 8443 으로 설정

Untitled

🔽 https://도메인 입력했을 경우, 배포한 사이트로 들어갈 수 있게 하기 위한 작업❗

  1. 프로젝트를 https에서 사용하기 위해 무료 SSL 인증서 발급

    sudo apt-get install letsencrypt
    
    sudo systemctl stop nginx
    
    sudo letsencrypt certonly --standalone -d www제외한 도메인 이름
    
  2. /etc/nginx/nginx.conf 파일에 인증서 경로를 포함한 모든 내용 작성

    /etc/nginx/sites-enabled/default, ... 등등 여러 파일이 있는데 ➡ 이 모든 파일은 nginx.conf 파일로 귀속?된다. 다른 파일을 사용할 것이라면 nginx.conf 에 include 로 path를 지정해줘야 한다.

    ⇒ 별다른 include를 하지 않고, /etc/nginx/nginx.conf 파일에 모조리 때려넣었다.

    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
    
        server {
            listen       80;
            server_name [YOUR_DOMAIN];
            client_max_body_size 30M;
            keepalive_timeout 5;
            return 301 https://$server_name$request_uri;
    
        }
        # HTTPS server
        server {
            listen       443 default_server ssl;
            server_name  [YOUR DOMMAIN];
    
            ssl_certificate      [YOUR_SSL_CERTIFICATE_LOCATION];
            ssl_certificate_key  [YOUR_SSL_CERTIFICATE_KEY_LOCATION];
            ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  5m;
    
            location / {
                 proxy_set_header X-Forwarded-For 		  $proxy_add_x_forwarded_for;
                 proxy_set_header X-Forwarded-Proto https;
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header HOST $http_host;
                 proxy_set_header X-NginX-Proxy true;
    
                 proxy_pass <https://127.0.0.1>:[YOUR PORT];
                 proxy_redirect off;
            }
        }
    }
    

    🎃🐶 결과 🐶🎃

    <aside> 💡 openvidu server : https://도메인:8443

    프로젝트 배포 url : https://도메인

    </aside>