프로그래밍 노트/인프라

[nginx] https(ssl) 설정 - 인증서체인설정

깡냉쓰 2020. 4. 28. 22:21
728x90
반응형

SSL 설정

upstream backend{ # upstream 설정
  ip_hash;
  server 127.0.0.1:9000 fail_timeout=30s;
}

server{
  listen 80;
  server_name www.corn-sample.com corn-sample.com;

  location / {
    root /usr/local/var/www/frontend;
    index index.html;
  }

  location ^~/api {
    proxy_pass http://backend;
  }

  error_page 500 502 503 504 /50x.html;
  location /50x.html {
    root html;
  }
}

server{
  #listen 443;
  listn 443 ssl;
  server_name www.corn-sample.com corn-sample.com;
  root /usr/local/var/www/frontend;

  location ^~/api{ # 요청이 /api로 시작하면 tomcat(backend)로 요청을 넘긴다.
    proxy_pass http://backend;
  }

  #ssl on;
  ssl_certificate /Users/sunghyun/cert/corn-sample.com.crt; # 인증서 경로
  ssl_certificate_key /Users/sunghyun/cert/corn-sample.com.key; # pirvateKey 경로
  ssl_session_timeout 5m;
  ssl_protocols SSLv2 SSLv3 TLSv1;
  ssl_ciphers HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers on;
}

SSL chain 구성

SSL 인증서 발급 기관이 브라우저에 기본 포함되지 않아서 인증서의 root CA를 찾지 못하는 경우가 있다.

cert1

Apache에는 SSLCaCertificateFile이라는 지시자가 있지만 nginx에는 없으므로 SSL인증서와 CA인증서를 하나의 파일로 만들어야 한다.

$ cat ./corn-sample.com.crt ./rootca.crt > ./corn-sample.com.chained.crt

(rootca.crt는 openssl을 이용해서 만든 rootCA의 인증서이며, corn-sample.com.crt는 rootCA의 서명이 들어가 있는 인증서이다.)
주의해야할 점은 SSL 인증서가 첫 번째로 와야한다.

합쳐진 인증서는 nginx ssl_certificate를 통해 지정해 주면 SSL chain을 구성할 수 있다.

ssl_certificate /Users/sunghyun/cert/corn-sample.com.chained.crt;

cert2

위와 같이 설정을 하면 서버 재기동시에, PEM 개인키의 암호를 계속 물어보게 되는데 해결방법이 2가지 존재한다.

  1. passphrase를 지운다. (privateKey의 암호를 제거하는 방법)
  2. SSL PasswordFile을 사용하는 방법
    ssl_password_file /var/lib/nginx/ssl_passwords.txt;

ssl_passwords.txt

echo '패스워드'

 

728x90
반응형