Answer the question
In order to leave comments, you need to log in
Nginx: code 503 in config actually turns out to be 302. Why?
server {
listen $ip:$port;
server_name example.com;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
error_page 503 http://example.com/maintrance.html;
return 503;
}
location = /maintrance.html {
return 200;
}
server {
listen $ip:$port;
server_name example.com;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
error_page 503 /maintrance.html;
return 503;
}
# Без этого локейшна в такой конфигурации сервер отдаёт не ту страницу для 503:
location /maintrance.html {
return 200;
}
}
Answer the question
In order to leave comments, you need to log in
Since your URL in error_page is specified with http and domain, an external redirect is implied. Hence 302. To get what you want, write
Also, if you want to get 200 in the response, it is not necessary to describe a separate location, you can solve the same error_page, it will be like this
And then location = /maintrance.html can be thrown out .
UPD: Yes, I did. Since error_page makes an internal redirect, if there is no separate location /maintrance.html - the server again falls into location / and an endless cycle of redirects is obtained. So in this case location /maintrance.html is needed.
Along the way, I want to focus on another method, more popular, especially if we do not need to issue 503.
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files /maintrance.html $uri $uri/ =404;
}
Maybe it's internal? As it were, 503 is Service Unaviable, and instead of returning to /maintrance.html you send it.
And he already gives 200.
Try removing:
location = /maintrance.html {
return 200;
}
Solution with expected behavior:
server {
listen $ip:$port;
server_name example.com;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
error_page 503 /maintrance.html;
return 503;
}
# Без этого локейшна в такой конфигурации сервер отдаёт не ту страницу для 503:
location /maintrance.html {
return 200;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question