Customized error pages for 500.

Igor Sysoev igor at sysoev.ru
Wed Jul 28 10:45:09 MSD 2010


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

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

     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 Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list