0

Running Nginx 1.4.1 I have the following config to display a custom error page in case my backend messes up. The page is displayed but custom fonts & images are not loaded. My custom error page (50x.html) is in /usr/share/nginx/html/. Static contents in subfolders img & fonts.

From my browser I can see that the static contents url is append to my current url which makes them unavailable. For instance if I'm browsing www.domain.com/user/account, Nginx will try to load content from the server :

URL 
/user/account/img/logo.png
/user/account/img/main.jpg
/user/account/img/footer.png
/user/account/fonts/miso-regular-webfont.ttf

Instead of from sr/share/nginx/html/img/

Here is the configuration portion :

error_page 324 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
                allow all;
                internal;
    }

Thanks for you lights.

EDIT 1 :

Thanks Alexey, path are now corrects but images still not displayed. At first backend failure, Nginx tries to fetch images from Apache whereas Nginx should serves the whole maintenance page and not relies on the backend. Why this behavior ? When a backen goes sick I can't rely on it, even for a maintenance page.

Thank you.

3
  • 1
    fix 50x.html to use absolute urls for images/styles. E.g. instead if <img src="img/logo.png"> there should be <img src="/img/logo.png"> and so on…
    – Alexey Ten
    Apr 2, 2015 at 14:47
  • Where is the rest of your nginx configuration? Show the complete server block. Apr 3, 2015 at 6:30
  • Re: Edit 1, requests for images/styles are completely separate from original request. Nginx has no idea that they are from error page. Just ask youself how nginx should guess that request for /img/logo.png is from error page and should be served somewht specially?
    – Alexey Ten
    Apr 3, 2015 at 7:01

1 Answer 1

2

Solved it with the following :

error_page 324 500 502 503 504 = @maintenance;
location @maintenance {
        root /usr/share/nginx/html;
        try_files $uri /50x.html =503;
}
1
  • I'm trying to follow your solution but nginx doesn't send a 503 this way. It appears as 200?
    – cortopy
    Sep 25, 2015 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .