# Customized error pages for 500

**URL:** <https://www.ruby-forum.com/t/customized-error-pages-for-500/191965>\
**Category:** NGINX\
**Created:** [July 21, 2010, 12:32pm UTC](https://www.ruby-forum.com/t/customized-error-pages-for-500/191965 "2010-07-21T12:32:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![schand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@schand](https://www.ruby-forum.com/u/schand)\
**Post date:** [July 21, 2010, 12:32pm UTC](https://www.ruby-forum.com/t/customized-error-pages-for-500/191965/1 "2010-07-21T12:32:57Z")

</div>

Hi, I am a newbie to nginx. I need to have a customized error pages for  
the http response codes 50x. I am running on nginx with passenger and  
ruby on rails. I have problem with nginx.conf. I am not able to get my  
customized 500.html page when the http error code is 500. I have tried a  
lot but none of them seemed to work or I ran into other issues. I have  
pasted my nginx.conf below. This is what I have right now in my server  
and is working fine. What exactly to be added to the conf file to make  
it work. Can some one help me out. All the pages are ‘https’.

In the access log I can see the entries:

[20/Jul/2010:11:38:49 +0000] “GET / HTTP/1.1” 500 193 “-” "Mozilla/5.0  
(X11; U; Linux i686; en-US; rv:1.9.2.6)

But I am not bale to see the customized 500 page. I can see the nginx  
500 page.

Thanks in advance. It will be very helpful to me.

BELOW IS THE NGINX CONF I HAVE RIGHT NOW.

#############################  
nginx.conf  
#########################

#user nobody;  
worker\_processes 1;

#error\_log logs/error.log;  
#error\_log logs/error.log notice;  
#error\_log logs/error.log info;

#pid logs/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
passenger\_root /path/to/gems/passenger-2.2.11;  
passenger\_ruby /usr/bin/ruby1.8;  
passenger\_pool\_idle\_time 0;  
rails\_spawn\_method smart;  
rails\_framework\_spawner\_idle\_time 0;  
rails\_app\_spawner\_idle\_time 0;

```
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local]

```

$request ’  
# '“$status” $body\_bytes\_sent “$http\_referer” ’  
# ‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css

```

application/x-javascript text/xml application/xml application/xml+rss  
text/javascript;  
client\_max\_body\_size 8M;

```
server {
    listen 80;

```

server\_name [mysite.com](http://mysite.com);

root /mysite/com/public;  
passenger\_enabled on;  
error\_page 500 502 503 504 /50x.html;  
location = /50x.html {  
root html;  
}

```
}

```

server {  
listen 443;  
server\_name [mysite.com](http://mysite.com);

```
    root /mysite/com/public;
    passenger_enabled on;

    ssl on;
    ssl_certificate /path/to/conf/mysite.crt;
    ssl_certificate_key /path/to/conf/mysite.key;

    ssl_session_timeout 5m;

    ssl_protocols SSLv2 SSLv3 TLSv1;
    ssl_ciphers

```

ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;  
ssl\_prefer\_server\_ciphers on;

if ($request\_filename ~\* .(css|jpg|gif|png)$) {  
break;  
}

if ($request\_filename = $document\_root/system/maintenance.html) {  
break;  
}

if (-f $document\_root/system/maintenance.html) {  
rewrite ^(.\*)$ /system/maintenance.html last;  
break;

}

error\_page 500 502 503 504 /500.html;  
location = /500.html{  
root /mysite/com/public;  
}

```
}

```

}

---

<div class="post-metadata">

**Author:** ![schand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@schand](https://www.ruby-forum.com/u/schand)\
**Post date:** [July 28, 2010, 7:04am UTC](https://www.ruby-forum.com/t/customized-error-pages-for-500/191965/2 "2010-07-28T07:04:10Z")

</div>

Can someone help me…

-Sarat

---

<div class="post-metadata">

**Author:** ![schand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@schand](https://www.ruby-forum.com/u/schand)\
**Post date:** [July 28, 2010, 8:46am UTC](https://www.ruby-forum.com/t/customized-error-pages-for-500/191965/3 "2010-07-28T08:46:23Z")

</div>

On Wed, Jul 21, 2010 at 12:32:57PM +0200, Saratchand Kanuri wrote:

> #############################  
> #pid logs/nginx.pid;  
> passenger\_pool\_idle\_time 0;  
> # ‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;  
> gzip\_http\_version 1.0;
> 
> server {  
> ssl\_session\_timeout 5m;  
> if ($request\_filename = $document\_root/system/maintenance.html) {  
> location = /500.html{  
> root /mysite/com/public;  
> }
> 
> ```
> }
> 
> ```
> 
> }

```
 server {
     listen 80;
     server_name mysite.com;

     root /mysite/com/public;
     error_page 500 502 503 504 /50x.html;

     location / {
         passenger_enabled on;
     }

     location = /50x.html {
         root html;
     }
 }

 server {
     listen 443;
     server_name mysite.com;

     # ... ssl stuff

     root /mysite/com/public;
     error_page 500 502 503 504 /500.html;

     location / {
         try_files /mysite/com/public/system/maintenance.html
                    $uri
                    =404;
         passenger_enabled on;
     }

     location ~* \.(css|jpg|gif|png)$ {
     }

     location = /500.html {
     }
}

```

–  
Igor S.  
[http://sysoev.ru/en/](http://sysoev.ru/en/)

---

<div class="post-metadata">

**Author:** ![schand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@schand](https://www.ruby-forum.com/u/schand)\
**Post date:** [August 2, 2010, 10:57am UTC](https://www.ruby-forum.com/t/customized-error-pages-for-500/191965/4 "2010-08-02T10:57:44Z")

</div>

Hi Igor S., Thank you for your reply. I made the change suggested  
by you. But it is showing me the nginx 404 error page for every request.

-Sarat

---

<div class="post-metadata">

**Author:** ![schand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@schand](https://www.ruby-forum.com/u/schand)\
**Post date:** [August 2, 2010, 11:43am UTC](https://www.ruby-forum.com/t/customized-error-pages-for-500/191965/5 "2010-08-02T11:43:43Z")

</div>

On Mon, Aug 02, 2010 at 10:57:44AM +0200, Saratchand Kanuri wrote:

> Hi Igor S., Thank you for your reply. I made the change suggested  
> by you. But it is showing me the nginx 404 error page for every request.

Could you create a debug log:  
[http://nginx.org/en/docs/debugging\_log.html](http://nginx.org/en/docs/debugging_log.html)  
of the requests ?

–  
Igor S.  
[http://sysoev.ru/en/](http://sysoev.ru/en/)

---

<div class="post-metadata">

**Author:** ![schand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@schand](https://www.ruby-forum.com/u/schand)\
**Post date:** [January 10, 2014, 1:19am UTC](https://www.ruby-forum.com/t/customized-error-pages-for-500/191965/6 "2014-01-10T01:19:11Z")

</div>

Igor S. wrote in post #928721:

> ```
> error_page 500 502 503 504 /500.html;
> 
> ```

[snip]

> ```
> location = /500.html {
> }
> }
> 
> ```

I would like to clarify what’s going on in these two lines of Igor’s  
answer.

A. Note the “/500.html” part on the first line. That is not a variable  
of any sort, but rather means that Nginx is expecting there to be a file  
named 500.html in your root. In some examples you will see “/50x.html”  
used instead. In that case, there must be a file that is literally named  
“50x.html” in your root. (The “x” is not to be mistaken for a variable)

B. Note the “location = /500.html” block down below. There is nothing in  
this block, but it is crucial that this block exists or your custom  
error page will not be displayed.
