Answer the question
In order to leave comments, you need to log in
nginx config: Mysterious redirect loop when using a variable in the server_name directive. Where are the loot?
Hello. Faced with mysticism.
There is a config (one file):
server {
server_name www.test.ru;
return 301 http://test.ru$request_uri;
}
server {
set $somevar test.ru;
listen 80;
server_name $somevar;
root /var/www/$somevar;
..и др.
server {
server_name www.test.ru;
return 301 http://test.ru$request_uri;
}
server_name test.ru;
Answer the question
In order to leave comments, you need to log in
The `server_name` directive cannot contain variables.
As a result, you have two servers, one named `www.test.ru`, the second named `$somevar`.
The request to the `test.ru` server does not find a server with the same name, gets to the default server, in this case the first one, and an endless redirect is obtained.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question