In nginx, we wish to redirect all requests sent to:
https://www.<domain>
http://www.<domain>
http://<domain>
To:
https://<domain>
ie SSL, without the www prefix, as a catch-all, without specifying each domain individually.
The config we have come up with nearly works:
server {
server_name "~^www\.(.*)$" ;
return 301 https://$1$request_uri ;
}
server {
listen 80 default;
client_max_body_size 10m;
client_body_buffer_size 128k;
return 301 https://$host$request_uri;
}
server {
listen 443;
ssl on;
..... etc ......
...but the first server block (the www catch) seems to be matching all requests, and not just the ones that are www.*