How to set Retry-After for 503?

Gena Makhomed gmm at csdoc.com
Fri Jul 3 23:46:09 MSD 2009


On Friday, July 3, 2009 at 21:01:18, tmiskiew wrote:

t> Can you please explain how to set Retry-After for the status code 503?

workaround via ngx_http_perl_module:

> cat /etc/nginx/perl/erorr503.pm
package error503;
use warnings;
use strict;
use nginx;

sub handler {
    my $r = shift;
    $r->status( 503 );
    $r->header_out( 'Retry-After', 600 );
    $r->send_http_header( 'text/html' );
    $r->print(
        "<html>"."\x0d\x0a".
        "<head><title>503 Service Temporarily Unavailable</title></head>"."\x0d\x0a".
        "<body bgcolor=\"white\">"."\x0d\x0a".
        "<center><h1>503 Service Temporarily Unavailable</h1></center>"."\x0d\x0a".
        "<hr><center>nginx</center>"."\x0d\x0a".
        "</body>"."\x0d\x0a".
        "</html>"."\x0d\x0a"
    );
}

1;

> cat /etc/nginx/conf/nginx.conf
# ...
http {
    server_tokens off;
    perl_modules  /etc/nginx/perl;
    perl_require  erorr503.pm;

    server {
        server_name error503;
        error_page 503 = @error503;
        location @error503 { perl error503::handler; }
        location /error503 { return 503; }
    }
# ...

> curl http://error503/error503 -D headers
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body bgcolor="white">
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>nginx</center>
</body>
</html>

> cat headers
HTTP/1.1 503 Service Temporarily Unavailable
Server: nginx
Date: Fri, 03 Jul 2009 19:30:47 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Retry-After: 600

-- 
Best regards,
 Gena






More information about the nginx mailing list