▼ DevOps

Nginx | HTTPS, SSL 인증서 적용하기

Valar 2022. 1. 11. 20:37
반응형

Windows 10 | nginx 설치하기

Linux AMI(CentOS)에 Nginx 설치하기

 

Nginx Version 1.20.2

Nginx가 이미 설치되었다는 가정 하에 conf 파일을 수정한다.

 

Windows

설치 경로/nginx/conf에 있는 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  example.com;

        location / {
            #301은 모든 트래픽을 리다이렉션 하는데 사용된다.
            #모든 http 요청을 https로
            return 301 https://$server_name$request_uri;
        }
    }

    server {
        listen       443 ssl;
        server_name  example.com;
		
        ssl_certificate      cert.pem;
        ssl_certificate_key  cert.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index  index.html index.htm;
            # Nginx 배포 시 Route 에서 404 에러 날때
        	try_files $uri $uri/ /index.html;
        }
    }
}

 

Linux

설치 경로/nginx/conf.d에 있는 default.conf 파일

 

server {
    listen       80;
    server_name  example.com;

    location / {
        #301은 모든 트래픽을 리다이렉션 하는데 사용된다.
        #모든 http 요청을 https로
        return 301 https://$server_name$request_uri;
    }
}

server {
    listen       443 ssl;
    server_name  example.com;

    ssl_certificate      certificate.crt;
    ssl_certificate_key  private.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
    
    location / {
        root   html;
        index  index.html index.htm;
        # Nginx 배포 시 Route 에서 404 에러 날때
        try_files $uri $uri/ /index.html;
    }

    error_page  404              /404.html;
    error_page  500 502 503 504  /50x.html;
    
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

 

 

반응형