I'm trying to migrate a site from HTTP to HTTPS, however, my nginx (version: 1.10.3) config seems not to be working.
The following behavior is desired:
http://www.example.com/path/to/content
should redirect tohttps://example.com/path/to/content
http://example.com/path/to/content
should redirect tohttps://example.com/path/to/content
https://www.example.com/path/to/content
should redirect tohttps://example.com/path/to/content
With my current config browsers wont connect to the site using HTTPS:
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
# redirects both www and non-www to https
rewrite ^(.*) https://www.example.com$1 permanent;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
# redirects non-www to www
rewrite ^(.*) https://www.example.com$1 permanent;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
charset utf-8;
# rest of my config
}
- What do I have to change to achieve the above mentioned behavior?
- Is it possible to accept (and later redirect) HTTP requests in a first step in order to keep the page "live" and let me test it?
- My site has very good SEO rankings (indexed as "http://www.example.com"), so properly redirecting is a must.