Nginx SSL 적용 http https 리다이렉트/리디랙션 처리 

 

http://[example.com] 로 접근 시, http 부분을 조회하여 https로 retrun 해주는 구문을 nginx로 적용.

    server { 
      ... 
      server_name example.com; 
      if ($http_x_forwarded_proto = 'http'){
          return 301 https://$host$request_uri;
      }
      
      location / {
	    proxy_pass http://tomcat;
	    proxy_set_header Host $host;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }

      location ~* \.(gif|jpg|png|js|css) {
          access_log off;
          proxy_pass http://tomcat;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
      
   }

server_name 아래로,

      if ($http_x_forwarded_proto = 'http'){
          return 301 https://$host$request_uri;
      }

부분을 추가해주고 nignx 서버를 재시작. 

[CENTOS 6.9 기준] service nginx restart 

완료.

 

 

+ Recent posts