N
N
nano_e_t_42016-09-25 01:21:57
Nginx
nano_e_t_4, 2016-09-25 01:21:57

How to write a config for a custom error_page page in nginx?

Hello everyone
I have a custom error_page page:

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel='stylesheet' type='text/css' href="../static/css/fonts.css">
  <link rel='stylesheet' type='text/css' href="../static/css/styles.css">
</head>
<body>
  <div class="top">
      <img src="../static/images/logo.png" width="250" height="60" alt="logo">
    </div>
    <div class="error">Thres is internal server error. Please write us</div>
    <div class="footer">
      </div>
    </div>
</body
</html>

there is also a config in nginx:
server {
    listen 80;
    server_name awsome_domain;
    recursive_error_pages on;
    access_log /var/log/nginx/awsome_domain.log;
    error_log /var/log/nginx/awsome_domain.log;

    error_page 500 501 502 503 504 /50x.html;
    location /50x.html {
        root /var/www/awsome_domain/;
    }
    location / {
        proxy_pass         http://127.0.0.1:88888/;
        proxy_redirect     off;
        proxy_set_header   Host                 $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;
    }
}

I drop the backend, request the main page, error_page is given but without styles and fonts. The browser says in the console when loading styles - 502 error. Moreover, if I just pull 50x.html from the console, then the page opens in the desired design and with fonts. Plz tell me where I clicked in the wrong place.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nano_e_t_4, 2016-09-25
@nano_e_t_4

everything turned out to be simple. it was necessary to register the root directory in the root :(. it is not entirely clear why he did not take it from the location

A
Anton Yankovsky, 2016-09-25
@webpavilion

This is how it should work:

...
error_page 500 501 502 503 504 = @customerror;

location @customerror {
        root /var/www/awsome_domain/;
        try_files $uri /50x.html = 503;
        #internal;
}
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question