I would like all traffic without the www, including https, to be redirected to the respective url with the www.
So http://example.com -> http://www.example.com, https://example.com -> https://www.example.com
There's plenty of info online about forcing ssl, which I do not want to do, and forcing www, but only for http. Just adding an s and changing the listen 80 -> listen 443 breaks the http sites. Here's my config so far:
server { listen 80; server_name example.com; location / { rewrite ^/(.*)$ http://www.example.com/$1 permanent; } } server { listen 80; server_name www.example.com; root /opt/example; index index.html; <locations stuff> } server { listen 443; server_name example.com; ssl on; ssl_certificate /opt/nginx/ssl/server.crt; ssl_certificate_key /opt/nginx/ssl/server.key; location / { rewrite ^/(.*)$ https://www.example.com/$1 permanent; } } server { listen 443; server_name www.example.com; root /opt/example; ssl on; ssl_certificate /opt/nginx/ssl/server.crt; ssl_certificate_key /opt/nginx/ssl/server.key; <locations stuff> }
swhere? Breaks the http sites how?