HTTPS redirects in nginx
Posted
by
CadentOrange
on Server Fault
See other posts from Server Fault
or by CadentOrange
Published on 2012-11-21T12:33:51Z
Indexed on
2012/11/21
17:02 UTC
Read the original article
Hit count: 233
I'm trying to redirect all HTTP traffic to HTTPS. The web server I'm using is nginx. This is the server block I'm using to do the redirect.
server {
listen 80;
rewrite ^ https://$server_name$request_uri? permanent;
}
This successfully redirects URLs like http://localhost
to https://localhost
. However, for URLs like http://localhost/table/
I get redirected to https://table
which is incorrect. I would like it to re-direct to https://localhost/table/
Any help would be much appreciated.
Update:
It seems that the rewrite scheme has a problem with trailing slashes. For example, http://localhost/table
gets correctly redirected but http://localhost/table/
does not.
© Server Fault or respective owner