TIP
nginx 에서 ssl 인증서 적용할때 제대로 되지 않을 경우에는 이렇게
judeKim'
2013. 12. 19. 16:47
반응형
nginx 와 haproxy를 써 LBS를 구축할 필요성이 생겼다.
현재 쓰고 있는 LBS가 성능은 모르겠으나, SSL을 지원하지 않아 Client 의 정보가 제대로 전달되지 못하는 경우가 발생하였고 이에 SSL offload 방식을 통해 client 정보를 전달하려고 했다.
haproxy 현재 버전(1.4)이 SSL을 지원하지 않는 상황때문에 어쩔수 없이 앞에 nginx를 두어야 했다.
( 1.5버전은 SSL을 공식지원하나 현재 개발중이라 production에는 적용하기 어렵다. )
SSL인증서를 적용해야 했고, 인증서 발급시 기존에 사용중인 apache 버전용 인증서를 받았으나 별 문제 없이 적용이 가능하겠지 생각했었으나 착각이었다.
그래서 찾은 방법이 다음과 같다.
#> cat cert.pem >> m.crt
#> cat RootCA.crt >> m.crt
#> cat ChainCA.crt >> m.crt
이렇게 3개의 파일을 위와 같은 순서로 하나의 파일로 만든다. ( 순서를 바꾸면 제대로 동작하지 않는다. )
nginx의 설정은 다음과 같다.
nginx > default.conf ( haproxy 설정이 포함 )
error_log /var/log/nginx/ssl_error.log debug;
access_log /var/log/nginx/ssl_access.log;
upstream haproxy {
server
IP
:port
;
}
server {
listen
443
ssl;
ssl_certificate ssl/xxx.com/m.crt;
ssl_certificate_key ssl/xxx.com/key.pem;
server_name api.xxx.com;
location / {
proxy_pass http:
//haproxy/;
proxy_set_header X-NginX-Proxy
true
;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect
default
;
proxy_read_timeout 15s;
proxy_connect_timeout 15s;
}
location ~ /\. { deny all; }
}
server {
listen
80
;
return
301
https:
//$host$request_uri;
}
이렇게 설정한뒤에 nginx 를 restart 해주면 다음과 같은 화면을 볼 수 있다.
반응형