0

I want to show one custom maintenance page for all errors. What code should I put to my nginx setting below? and the file of my nginx setting is located at /etc/nginx/conf.d/default.conf.

server {
    listen   80;
    listen [::]:80;
    server_name myip;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://myapp:8000;
    }

    location /static/ {
        alias   /myapp/static/;
    }

    location /media/ {
        alias   /myapp/media/;
    }
}

And this is my maintenance.html file below.

<!DOCTYPE html>
<title>Site Maintenance</title>
<style>
  body { text-align: center; padding: 150px; }
  h1 { font-size: 50px; }
  body { font: 20px Helvetica, sans-serif; color: #333; }
  article { display: block; text-align: left; width: 650px; margin: 0 auto; }
  a { color: #dc8100; text-decoration: none; }
  a:hover { color: #333; text-decoration: none; }
</style>

<article>
    <h1>We&rsquo;ll be back soon!</h1>
    <div>
        <p>Sorry for the inconvenience. We&rsquo;re performing some maintenance at the moment.</p>
    </div>
</article>

My maintenance.html looks like this on browsers.


enter image description here


0
  1. Put your maintenance.html file at /var/www/html/maintenance.html.

  2. Put the error_page line and location block showing below.


server {
    listen   80;
    listen [::]:80;
    server_name myip;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://myapp:8000;
    }

    location /static/ {
        alias   /myapp/static/;
    }

    location /media/ {
        alias   /myapp/media/;
    }

    ##### Put this code #####

    error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 /maintenance.html;

    location = /maintenance.html {
        internal;
        root /var/www/html;
    }

    ##########################
}

I referred to this website to solve your problem. The website teaches how to show one custom error page for all errors. I also referred to this website to get the code of maintenance.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.