# Custom error pages

**URL:** <https://www.ruby-forum.com/t/custom-error-pages/217794>\
**Category:** NGINX\
**Created:** [March 13, 2012, 2:39pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794 "2012-03-13T14:39:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 13, 2012, 2:39pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/1 "2012-03-13T14:39:31Z")

</div>

I’m using nginx to reverse proxy my web server. I want to be able to  
return a custom 503 page from nginx when I choose. I’m able to get  
nginx  
to return a 503 page by adding it to the top of the location. But that  
just returns the default nginx error page. How to do change this to a  
custom page?

Thanks.

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 14, 2012, 12:40am UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/2 "2012-03-14T00:40:57Z")

</div>

On Tue, Mar 13, 2012 at 09:38:56AM -0400, Bai Shen wrote:

Hi there,

> I’m able to get nginx  
> to return a 503 page by adding it to the top of the location. But that  
> just returns the default nginx error page. How to do change this to a  
> custom page?

Does [Module ngx\_http\_core\_module](http://www.nginx.org/r/error_page) give the info you need?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 14, 2012, 1:51pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/3 "2012-03-14T13:51:30Z")

</div>

IIRC, I tried that but wasn’t able to get nginx to find my local error  
page.

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 15, 2012, 3:48pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/4 "2012-03-15T15:48:41Z")

</div>

How do I get nginx to serve the page? I added in the line from the  
link,  
but I still get the default nginx page, not my custom one.

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 15, 2012, 8:24pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/5 "2012-03-15T20:24:59Z")

</div>

On Thu, Mar 15, 2012 at 10:48:13AM -0400, Bai Shen wrote:

Hi there,

> How do I get nginx to serve the page? I added in the line from the link,  
> but I still get the default nginx page, not my custom one.

# === server { error\_page 503 /my-503-error.html; location / { return 503; } location = /my-503-error.html { internal; } }

will serve the content of the file my-503-error.html in your document  
root with a http status 503 for (almost) every request to this server.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 16, 2012, 2:44pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/6 "2012-03-16T14:44:28Z")

</div>

I added this into my config file, and put my-503-error.html in the same  
location as the default 50x.html file, but all I get is a generic 404  
error  
page.

Is that not the document root for nginx?

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 16, 2012, 2:35pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/7 "2012-03-16T14:35:09Z")

</div>

I should still be able to use the listen and server\_name directives to  
have  
this apply to certain servers, correct?

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 16, 2012, 4:19pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/8 "2012-03-16T16:19:29Z")

</div>

On Fri, Mar 16, 2012 at 09:43:39AM -0400, Bai Shen wrote:

Hi there,

> I added this into my config file, and put my-503-error.html in the same  
> location as the default 50x.html file, but all I get is a generic 404 error  
> page.

You got an error page.

What does the error log say?

Either put your 503 file there; or configure “root” so that it is  
correct  
within this location{}.

If you’re still having problems, please follow the “debug” instructions  
to make it easier for people to help you.

Details on the web site, but in brief:

what did you do?  
what did you see?  
what did you expect to see?

and the more specific you are, the easier it will be for someone else to  
reproduce the problem you are reporting.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 28, 2012, 9:43pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/9 "2012-03-28T21:43:38Z")

</div>

I got my error page to show up. However, the css and image files don’t  
load. I tried changing the location, but that doesn’t seem to work.

Any suggestions?

Thanks.

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 16, 2012, 7:28pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/10 "2012-03-16T19:28:21Z")

</div>

Doh! I forgot 'bout the error log.

Apparently, nginx is looking for the file in /etc/nginx//html However,  
the  
default html files were installed in /usr/share/nginx/html

I installed from the repo, so I’m not sure why it installed in one place  
yet is looking in another. And I don’t have a root html directory set  
in  
any of the conf files.

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [March 28, 2012, 11:17pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/11 "2012-03-28T23:17:13Z")

</div>

On Wed, Mar 28, 2012 at 03:42:45PM -0400, Bai Shen wrote:

Hi there,

> I got my error page to show up. However, the css and image files don’t  
> load. I tried changing the location, but that doesn’t seem to work.
> 
> Any suggestions?

Try changing the location again. Maybe it will work this time.

Or alternatively:

Please fill in the details:

> > what did you do?

That will be something like “curl -i [http://myserver/myfile.css](http://myserver/myfile.css)”

> > what did you see?

That will be whatever you got back – the content of  
/var/tmp/myfile.css,  
or the content of another file, or some error message. There might be  
more details available in log files.

> > what did you expect to see?

That will be something like “http 200 and the content of  
/usr/local/nginx/html/myfile.css”.

> > and the more specific you are, the easier it will be for someone else to  
> > reproduce the problem you are reporting.

Provide the relevant part of nginx.conf from a machine where you saw  
the problem. If you don’t know what is the relevant part, provide the  
whole thing.

It doesn’t have to be your “live” config, but it should be a config that  
you ran on a test machine. The smaller the config, the better.

If you make it easy for someone to run the same server config as you,  
and run the same client commands as you, and see the same error output  
as you; then you make it easy for that person to try to help resolve the  
problem you saw.

If you don’t, you don’t.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Bai\_Shen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@Bai\_Shen](https://www.ruby-forum.com/u/Bai_Shen)\
**Post date:** [April 3, 2012, 10:13pm UTC](https://www.ruby-forum.com/t/custom-error-pages/217794/12 "2012-04-03T22:13:48Z")

</div>

My conf looks like this.

server {  
listen 192.168.1.1:80;  
server\_name [example.com](http://example.com);

error\_page 503 /maint/503.html;

location /maint/503.html {  
internal;  
}

location /maint/ {  
root /etc/nginx/html;  
}

server {  
listen 192.168.1.1:80;  
server\_name [example.com](http://example.com);

location / {  
proxy\_pass [http://192.168.1.2](http://192.168.1.2);  
}  
}

To show the 503 page instead of my site, I uncomment the top server  
block.  
When I want to bring the site back, I comment the top block out. The  
/maint/ location was what I changed to get the css and images to work.  
However, I’m not sure that it’s the best solution. Also, I’m assuming  
that  
there’s a better way to show/hide the 503 page than commenting out the  
whole server block.
