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.
Written by Kyle Isom
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nginx
Authors
reiaguilera
279.4K
jamesdullaghan
90.14K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#