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.

frenchviking
  • 77
  • 1
  • 3
  • 8
  • 1
    fix `50x.html` to use _absolute_ urls for images/styles. E.g. instead if `` there should be `` and so on… – Alexey Ten Apr 02 '15 at 14:47
  • Where is the rest of your nginx configuration? Show the complete `server` block. – Michael Hampton Apr 03 '15 at 06: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 03 '15 at 07:01

1 Answers1

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;
}
frenchviking
  • 77
  • 1
  • 3
  • 8