How can I have nginx return 204 when send_timeout is triggered?

Maxim Dounin mdounin at mdounin.ru
Wed Dec 10 14:13:32 UTC 2014


Hello!

On Wed, Dec 10, 2014 at 08:58:42AM -0500, meir.h at convertmedia.com wrote:

> Hello Maxim,
> 
> I am so sorry for not being clear.
> 
> My question is, can I have the nginx submit a 204 to the client after a
> predefined time?

Yes, but that's not a trivial task when using vanilla nginx.  For 
example you can do this using the embedded perl module, 
$r->sleep() command:

    
    location / {
        perl 'sub {
            my $r = shift;
            $r->discard_request_body;

            sub next {
                my $r = shift;
                $r->status(204);
                $r->send_http_header;
            }

            $r->sleep(1000, \&next);
        }';
    }

See http://nginx.org/r/perl for more details.

This can be also done using 3rd party modules.  E.g., using the 
delay module as available from http://mdounin.ru/hg/ngx_http_delay_module/, 
this can be done as follows:

    location / {
        delay 2s;
        error_page 403 = /empty;
        deny all;
    }

    location = /empty {
        return 204;
    }

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list