Customized error pages for 500

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;

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;

    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;
}

}

}

Can someone help me…

-Sarat

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/

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

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
of the requests ?


Igor S.
http://sysoev.ru/en/

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs