ubuntu
환경에서 자주사용하는 nginx
명령어 정리 및 nginx.conf
설정 정리
링크: http://nginx.org/en/docs/http/ngx_http_proxy_module.html
server {
...
location / {
# 요기부터
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass <url>
# 요기까지 추가하면 됨
proxy_redirect off;
}
...
여기서 핵심은 using secure sessions behind an http proxy이 링크에 잘 설명되어 있다.
핵심은 proxy_set_header X-Forwarded-Proto $scheme
이다.
Of course, but everything is also served via an ELB which proxies to our nginx cluster, which in turn proxies to our apps servers via internal http connections. The fix is trivial as it’s easy to set/modify headers in nginx, making the header validation in Connect quite pointless – proxy_set_header x-forwarded-proto https;.
In completely unrelated news, sessions on GoSquared now use secure + httponly cookies!
PS. remember to add proxy_set_header Host $host; too if you need the host header to be forwarded too, it appears to get lost otherwise.
내부적으로는 http connection으로 프록시 된다. 따라서 cookie secure를 해주려면 proxy_set_header x-forwarded-proto https 설정을 해줘야한다. 또한 host header를 전달해주려면 proxy_set_header Host $host 설정도 해줘야한다.
에러로그는 nginx
설정 파일에 보면 어디에 로그가 쌓이는지 확인 가능하다.