April 24, 2009

Nginx and Passenger, Gateway Timeout Fix

I recently switched an application I am working on from nginx and mongrel to nginx and passenger. The setup is easy as can be but I noticed an issue on one of my long running operations. I have a controller that spawns some threads, performs operations and returns back a result to the page. Sometimes this takes a minute and using mongrel you would just increase the proxy_read_timeout in nginx. With passenger it times out after 60 seconds. There is not a configuration parameter for adjusting this. I found that adjusting upstream.read_timeout and upstream.send_timeout in /usr/lib/ruby/gems/1.8/gems/passenger-2.2.1/ext/nginx/Configuration.c (below) to a higher value and reinstalling the passenger module solves the problem.

/usr/lib/ruby/gems/1.8/gems/passenger-2.2.1/ext/nginx/Configuration.c

::snip::
ngx_conf_merge_msec_value(conf->upstream.send_timeout,
prev->upstream.send_timeout, 60000);

ngx_conf_merge_msec_value(conf->upstream.read_timeout,
prev->upstream.read_timeout, 60000);
::snip::

Thanks to the passenger team and the quick response on the mailing list.

4 Comments

  1. baldrailers Jun 02, 2009 12:32 am

    How do you reinstall the passenger module? And what configuration should be made on the http part of nginx.conf?

  2. joe Jun 02, 2009 9:02 am

    Basically re-running the nginx/passenger install should do it. It needs to compile the changes into the nginx-passenger module. No changes need to be made to your nginx config if you already are using nginx/passenger.

  3. Luke Nov 04, 2009 12:55 pm

    @joe: You said “Basically re-running the nginx/passenger install should do it.” Does this mean I need to reinstall nginx?

    Note I am running apache/passenger/nginx. I’m not sure if this is the same as your setup.

    Thanks!

  4. joe Nov 04, 2009 1:29 pm

    Yeah, you need to reinstall the passenger nginx module after making the timeout change.

Leave a Comment

(required)

(will not be published) (required)