hieuhtr / Blog

Don’t be lazy. Don’t make excuses. No one cares. Work fucking harder.
Other
6 stars 2 forks source link

Force HTTPS in NGINX #79

Open hieuhtr opened 7 years ago

hieuhtr commented 7 years ago

Goal

Redirect http to https

server {
   # all traffic, secure or otherwise, comes in on 80 from the ELB
   listen 80;

   # ELB stores the protocol used between the client 
   # and the load balancer in the X-Forwarded-Proto request header.
   # Check for 'https' and redirect if not
   if ($http_x_forwarded_proto != 'https') {
       rewrite ^ https://$host$request_uri? redirect;
   }

   server_name  your-secure-site.com  www.your-secure-site.com;

.... (the rest of your config)
}

Reference

https://codyparker.com/force-entire-site-ssl-nginx-behind-aws-load-balancer/