Redirect all traffic to https in nginx

If you have enabled https, have a public IP and want to redirect all traffic from http to https you can change the "/ location {}" section in nginx.conf to the following.

location / {
  rewrite ^ https://$host$request_uri? permanent;
}

If you do not have your own public IP and use the shared SSL certificate then add the following lines to the "/ location {}" section.


if ($http_x_forwarded_proto != "https") {
  rewrite ^ https://$host$request_uri? permanent;
}

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Article is closed for comments.