Suggestions on how to have error pages based on content type

Zev Blut zblut at cerego.co.jp
Tue Oct 27 05:10:06 MSK 2009


Hello,

I take it, what I am trying to do is not possible?

Thanks,
Zev

On 10/24/2009 05:30 PM, Zev Blut wrote:
> Hello,
>
> I am wondering if it is possible to serve up error pages based on the
> content type.
>
> I.e. I want to show a different 503 error page for html, xml and
> javascript content types.
>
> I have tried to do something like this (with Nginx 0.6 series):
> ---------------------------
>
> server {
>      listen       80;
>
>      charset off;
>      server_name errortest.localhost;
>
>      root /var/www/foobar/nginx_error_test;
>
>      if (-f /var/www/foobar/nginx_error_test/maintenance_on.html) {
>        rewrite  ^(/images/.*)$  /images/server-maintenance.png break;
>        return 503;
>        break;
>      }
>
>      error_page   503 /system/maintenance;
>
>      location = /system/maintenance {
>        auth_basic off;
>        root /var/www/foobar/nginx_error_test/system;
>
>        if ($content_type ~* javascript) {
>          rewrite . /system/maintenance.json break;
>        }
>
>        if ($content_type ~* xml) {
>          rewrite . /system/maintenance.xml break;
>        }
>
>        rewrite . /system/maintenance.html break;
>      }
>
>      if (-f $request_filename) {
>         break;
>      }
>
>      if (-f $request_filename.html) {
>         rewrite (.*) $1.html break;
>      }
>
> }
>
> ---------------------------
>
> Unfortunately, this does not work.  All that happens is I get the
> standard Nginx 503 html error response.
>
> Any ideas if I can do this and if so what I am doing wrong?
>
> Thanks,
> Zev
>






More information about the nginx mailing list