How to accomplish proxy_connect_timeout of less than 1 second

807 views
Skip to first unread message

James Marlowe

unread,
Mar 20, 2014, 10:43:25 AM3/20/14
to openre...@googlegroups.com
We run a very time constrained process that needs to connect to another server where the best way seems to be through a proxy_pass. The time-out time we need is less than 1 second though.

using proxy_connect_timeout 0.25s; throws 'nginx: [emerg] "proxy_connect_timeout" directive invalid value' which I expected, but I can't think of a good way to accomplish the same thing.

Is there something we can do?

James Marlowe

unread,
Mar 20, 2014, 11:04:34 AM3/20/14
to openre...@googlegroups.com
After posting that I see that setting it like proxy_connect_timeout 250ms; works.

Now I also see lua_socket_connect_timeout which might make more sense since I am calling the proxy location from a ngx.location.capture (assuming that imposes the limit like I would expect). Maybe I should use both so that the nginx process to connect to the remote ends and the lua process to connect to the local url ends?

Yichun Zhang (agentzh)

unread,
Mar 20, 2014, 2:47:38 PM3/20/14
to openresty-en
Hello!

On Thu, Mar 20, 2014 at 8:04 AM, James Marlowe wrote:
> After posting that I see that setting it like proxy_connect_timeout 250ms;
> works.
>

Yes, this is the right syntax.

And don't forget to configure proxy_send_timeout and
proxy_read_timeout at the same time. Otherwise you're only limiting
the connection establishing time.

> Now I also see lua_socket_connect_timeout which might make more sense since
> I am calling the proxy location from a ngx.location.capture (assuming that
> imposes the limit like I would expect). Maybe I should use both so that the
> nginx process to connect to the remote ends and the lua process to connect
> to the local url ends?
>

NGINX subrequests do not have timeout mechanism themselves and they do
not involve any socket operations on their own. NGINX subrequests are
C function calls per se.

So lua_socket_connect_timeout has nothing to do with ngx.location.capture*.

Regards,
-agentzh

James Marlowe

unread,
Mar 20, 2014, 2:54:42 PM3/20/14
to openre...@googlegroups.com
Great thank you so much for the tips.
Reply all
Reply to author
Forward
0 new messages