nginx

broccoli·2021년 5월 14일
0

nginx

목록 보기
1/1
post-thumbnail

ubuntu환경에서 자주사용하는 nginx명령어 정리 및 nginx.conf설정 정리

  1. nignx_http_prox_module 설명
  2. reverse proxy사용시 cookie secure사용하는 법
  3. 우분투에서 자주사용하는 nginx command line
  4. nignx logs 확인법

1. nginx_http_proxy_module 설명

링크: 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 이다.

Why does this matter? Isn’t everything is served via https anyway?

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 설정도 해줘야한다.

3. 우분투에서 자주사용하는 nginx command line

  • nginx 시작: sudo systemctl start nginx
  • nginx 상태 확인: sudo systemctl status nginx
  • nginx 재시작: sudo systemctl restart nginx

4. nginx logs 확인법

에러로그는 nginx설정 파일에 보면 어디에 로그가 쌓이는지 확인 가능하다.

참고링크

profile
🌃브로콜리한 개발자🌟

0개의 댓글