Last Updated: February 25, 2016
·
1.206K
· kisom

Redirect http to https in nginx

If you have an https server set up:

server {
 listen 443;
 server_name foo.bar;
 ...
}

you can add an http server with a rewrite:
server { listen 80; server_name foo.bar; rewrite ^(.*) https://$host$1 permanent; }

Of course, we do want a permanent redirect as there is nothing else being served over http, and it encourages users to use the secured version.