Strange Keepalive behavior

Skip to first unread message

Jakob Braun

Jan 17, 2024, 9:05:29 AMJan 17



I set up openresty as dynamic reverse proxy as described here:


Here is my example config narrowed down to the problem:

server {
   listen       80;

   location /proxy {
       set $proxy "";
       rewrite_by_lua '
           ngx.var.proxy = "";
       proxy_redirect     off;
       proxy_set_header   Host $host;

  location  /unused {
    proxy_redirect     off;
    proxy_set_header   Host $host;


My upstream servers are contacted via https.


Now I’m measuring the performance of a request. With a plain nginx reverse proxy I experienced the behavior that the first request takes ~1s and the second one only 0.1s.

Now I expected the same on openresty, but here each request takes ~1s.

The strange thing is that when I change the in the /unused location to the following requests to /proxy are fast, even so I the route is not even used.


I guess this is because openresty then implicitly knows that there is an upstream and does some http keepalive.


Does someone understand this and can g8ive me a hint how to make also the /proxy fast?




Junlong li

Jan 17, 2024, 9:30:46 PMJan 17
to openresty-en
You can use tcpdump to check if the second request used the keepalive connection.

For the keepalive connection, I think you need to use the upstream config block. Go to for more details.

You also need to set the following two headers:

location /proxy {
  # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
  proxy_http_version 1.1;

  # Remove the Connection header if the client sends it,
  # it could be "close" to close a keepalive connection
  proxy_set_header Connection "";

Jakob Braun

Jan 18, 2024, 5:22:46 AMJan 18



thank you for your reply.

I’ve now checked the keepalive connections. Surprisingly, none of the variants seems to use keepalives.


I guess the performance difference must be caused by something different. I’ve seen in the doc the option proxy_ssl_session_reuse on;

So, I had the idea that openresty maybe caches the SSL session under the hood. But setting this in the Lua handler did also not help.


Also setting the other options you suggested did not make a difference.





Von: <> Im Auftrag von Junlong li
Gesendet: Donnerstag, 18. Januar 2024 03:31
An: openresty-en <>
Betreff: [openresty-en] Re: Strange Keepalive behavior


Sie erhalten nicht oft eine E-Mail von Erfahren Sie, warum dies wichtig ist

You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Reply all
Reply to author
0 new messages