R
R
Rad1us2016-07-11 10:47:43
linux
Rad1us, 2016-07-11 10:47:43

How to set up a 503 error page in NGINX?

I'm setting everything up for the first time. I have Debian with nginx installed. It is required that nginx give one page with a 503 error. The folder with html, styles and pictures is in the root - /site, nginx.conf is now like this:

server {
     listen 80;
     server_name localhost;
    
     error_page 503 /503.html;
     location = /503.html {
          root /site;
     }

     location / {
          return 503;
     }
}

The problem is that in this configuration the page is displayed, but without styles and images. How to fix?
PS: I have already read similar questions, but what was recommended there did not help me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Misbakh-Soloviev, 2016-07-28
@mva

$  cat /etc/nginx/templates.d/errors
error_page        401     /401;
error_page        402     @402;
error_page        403     /403;
error_page        404     /404;
error_page        500     /500;
error_page        502     /502;
error_page        503     /503;
error_page        504     /504;
error_page        582     /582;

location ~* /(401|403|404|500|502|503|504|582) {
        internal;
        allow all;
        default_type    text/html;
        root                    /var/www/__default__/sites/default;
}

location @402 {
#   internal;
        allow all;
        default_type    text/html;
        echo                    '<center><b><font size="300%">HTTP Error 402</font></b></center>';
}

location ~ ^/errors/(.*) {
        alias /var/www/__default__/sites/default/media/$1;
        allow all;
        access_log off;
}
$  cat /var/www/__default__/sites/default/503
<html>
<head>
<title>Сервис недоступен</title>
<link rel="favicon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/errors/css/errors.css" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
</head>
<body>
<div id="center">
<div id="number">
5☺3
</div>
<div id="text">
Администратор сайта временно перевёл его в режим обслуживания.<br />
Скорее всего, в данную минуту на сайте производится обновление ПО.
<br />
Как вариант, сайт мог быть специально выключен администратором чтобы<br />
снизить нагрузку на сервер во время DDoS-атаки.
<br />
Пожалуйста, попробуйте зайти позже.
</div>
</div>
</body>
</html>
$  ls -l /var/www/__default__/sites/default/media/
итого 1
drwxr-xr-x. 2 nginx nginx 4096 июл  8  2014 css
drwxr-xr-x. 2 nginx nginx 4096 июл  8  2014 images

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question