Welcome! Log In Create A New Profile

Advanced

Re: auth_request sub requests not using upstream keepalive

Maxim Dounin
January 30, 2022 03:36PM
Hello!

On Fri, Jan 28, 2022 at 10:08:45PM -0800, Zach Rait wrote:

> I was exploring using auth_request from the ngx_http_auth_request_module,
> and I have encountered some unexpected behavior with regard to HTTP
> keepalive/connection reuse. I have some configuration that looks roughly
> like this:
>
> location = /auth_check {
> proxy_pass_request_body off;
> proxy_set_header Content-Length '';
> proxy_http_version 1.1;
> proxy_set_header Connection '';
> proxy_pass https://upstream_with_keepalive_confugred;
> }
>
> location /private {
> auth_request /auth_check;
> proxy_pass http://some_backend;
> }
>
> When I make a series of requests to /auth_check, nginx uses an existing
> connection as confirmed by tcpdump, but when I make a series of requests to
> /private, each /auth_check is closing the TCP connection at the end and
> then creating a new one for the following request. In my
> particular use-case this leads to approximately double the latency of the
> calls that use auth_request. Is this the expected behavior/a known issue
> with auth_request/http subrequests in general?

Make sure your backend uses "Content-Length: 0" or status code 204
in responses to auth subrequests.

Even with keepalive configured, nginx closes upstream connection
if the response contains the response body nginx is not going to
read, as it is often cheaper to reopen a connection than wait for
the unneeded response body.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
Subject Author Posted

auth_request sub requests not using upstream keepalive

Zach Rait January 29, 2022 01:14AM

Re: auth_request sub requests not using upstream keepalive

Maxim Dounin January 30, 2022 03:36PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 205
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready