Nginx SSL 설정

nginx 웹서버에 SSL을 적용하여 웹사이트에 https를 활성화하는 방법에 대해서 소개합니다.

웹사이트에 https를 적용하기 위해서는 nginx 웹서버에 ssl을 적용해야 합니다. 이 글에서는 nginx에서 간단하게 ssl 인증서를 적용하는 방법에 대해서 알아보도록 하겠습니다.

nginx.conf ssl 설정하기

https를 적용할 때, 보통은 http로 오는 요청과 https로 오는 요청 모두 응답할 수 있도록 설정을 하는데요. 아래는 nginx를 처음 설치했을 때 예시로 있는 설정 코드입니다.

server {
  listen       443 ssl;
  server_name  localhost;

  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;
  }
}

이렇게 따로 ssl 설정을 할 수도 있지만, 아래와 같이 http, https 동시에 설정을 해주는 것이 보기에도 편하고, 유지보수하기에도 편합니다.

server {
  listen       80;
  listen       443 ssl;
  server_name  www.example.com;

  ssl_certificate      {path}/cert.pem;
  ssl_certificate_key  {path}/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;
  }
  # some other configurations...
}

이 설정에서 중요한 속성은 ssl_certificatessl_certificate_key를 정확하게 설정해주어야합니다.

맺음

이렇게 nginx에서 SSL 설정하는 방법 대해서 정리해 보았습니다. 잘 못된 점이나 궁금한 점이 있으시면 댓글 부탁드리겠습니다.

감사합니다.