Answer the question
In order to leave comments, you need to log in
How to redirect from www in catch all block when server_name is not used?
With such settings, it knocks out the error "too many redirects" in the browser
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {}
}
server {
listen 80;
listen [::]:80;
server_name www.*;
return 301 $scheme://$host$request_uri;
}
Answer the question
In order to leave comments, you need to log in
server {
listen 80;
listen [::]:80;
server_name www.*;
return 301 $scheme://$host$request_uri;
}
server {
listen 80;
listen [::]:80;
server_name ~^www\.(?<domain>.+)$;
return 301 $scheme://$domain$request_uri;
}
map $host $domain {
~^www\.(.+) $1;
}
server {
listen 80;
listen [::]:80;
server_name www.*;
return 301 $scheme://$domain$request_uri;
}
why are you using default_server at all; ?
On it, put "hello this server, but something went wrong"
And for the site, make a normal separate file with a separate
server {
listen *:80;
server_name www.site.ru site.ru ;
root /var/www/site.ru/web;
.........
server {
listen *:443;
server_name www.site.ru site.ru ;
root /var/www/site.ru/web;
.........
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question