I have the following server
block in Nginx config:
server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
server_name _;
if ($scheme = http) {
return 302 https://$host$request_uri;
}
location / {
root /frontend/master;
index index.html;
try_files $uri $uri/ /index.html?$query_string;
}
}
So I already have redirect from http to https. But how to do redirect from www.example.com to example.com for this rule?
UPD: the most important thing here is that domains in our service are dynamic, our users register them by themselves and then chaining them via DNS settings. So I need to make a redirect to non-www without putting some domains in the server_name
variable.