Suggestions on how to have error pages based on content type

Zev Blut zblut at cerego.co.jp
Wed Oct 28 06:46:35 MSK 2009


Hi Phillip,

On 10/27/2009 05:02 PM, Phillip Oldham wrote:
> How about this (not tested)?
>> error_page 503 @maintenance;
>>
>> location @maintenance {
>> auth_basic off;
>> root /var/www/foobar/nginx_error_test/system;
>>
>> if ($content_type ~* javascript) {
>> rewrite . /system/maintenance.json last;
>> }
>>
>> if ($content_type ~* xml) {
>> rewrite . /system/maintenance.xml last;
>> }
>>
>> rewrite . /system/maintenance.html last;
>> }
>>
>> if (-f $request_filename) {
>> break;
>> }
>>
>> if (-f $request_filename.html) {
>> rewrite (.*) $1.html last;
>> }
>>
>> }

This is almost there!

Now when I do a request I will get the proper Content-Type response:

wget --header "Content-Type: application/javascript" -S -O - 
errortest.localhost/index.json
--12:40:31--  http://errortest.localhost/index.json
            => `-'
Resolving errortest.localhost... 127.0.0.3
Connecting to errortest.localhost|127.0.0.3|:80... connected.
HTTP request sent, awaiting response...
   HTTP/1.1 503 Service Temporarily Unavailable
   Server: nginx/0.6.35
   Date: Wed, 28 Oct 2009 03:40:31 GMT
   Content-Type: application/javascript
   Content-Length: 102
   Connection: keep-alive
12:40:31 ERROR 503: Service Temporarily Unavailable.


But unfortunately, the output is not my maintenance.json output, it is 
nothing in the case of wget and the default 500 internal server error in 
a browser.  Interestingly enough, the Content-Length is correct for the 
maintenance.(json|xml|html) for the proper setting.

Any ideas why it would not show the rewritten maintenance page?

Thanks,
Zev





More information about the nginx mailing list