Welcome! Log In Create A New Profile

Advanced

NGINX 503 custom error page. How to?

Posted by suchislife801 
NGINX 503 custom error page. How to?
April 09, 2011 03:57PM
Hello experts,

Although I have found of lot of info on how to get NGINX to return 503 customer error pages I have not been able to find out how to do the following:

Sample config file:

location / {
root www;
index index.php;
try_files /503.html = 503;
}

error_page 503 /503.html;
location = /503.html {
root www;
}

As you can see, according to the code above, if a page called error503.html is found in my root directory, the site will return this very page to the user.

The issue:

It seems that although the code above works when someone simply visits my site typing http://www.mysite.com, it DOES NOT TRAP a request like http://www.mysite.com/profile.php. With my code, the user can still see the profile page or any other pages besides index.php.

The question:

How do I trap requests to all pages in my site and forward them to error503.html whenever error503.html is present in my root folder?

Thank you for any help.
Re: NGINX 503 custom error page. How to?
April 14, 2011 05:24AM
To return a "503 temporarily not available, server in maintenance mode, dont worry we are coming back ;) " - page you can simply do:

location / {
return 503;
break;

root www;
index index.php;
}

You probably want to have the 503 without a change in your configuration by simply moving a 503.html into your doc root..

in the try_files documentation they have an example for this http://wiki.nginx.org/NginxHttpCoreModule#try_files

try_files 503.html @fallBackWhen503doesntExist;

location @fallBackWhen503doesntExist {
do your default stuff;
}

error_page 503 /503.html;
location /503.html
{
root www;
return 503;
}

I'd say this is bad practise ( if it works, didnt try ) because you will use the fallback ( error case ) to deliver your websites and each requests will check the existance of the 503 document in your docroot
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 151
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready