Skip to content

Conversation

WeidiDeng
Copy link
Member

If proxy protocol is enabled, keepalive was disabled because there was no known way to differentiate requests to the same upstream from different clients.

But caddy actually updates the url in the requests to point to the upstream, this url is then used to dial to the upstream unless if a proxy is used for this request, in which case the proxy url is used for the dial.

We can update the url to add unique identifiers to create a mapping between the client address and the upstream address so that connections can be kept alive and requests from different clients to the same upstream won't interfere with each other.

Using the following caddyfile:

{
    debug
    skip_install_trust
    local_certs
    servers :9080 {
        listener_wrappers {
            proxy_protocol {
                allow 192.168.100.103/24
            }
        }
    }
}

localhost {
    reverse_proxy 192.168.100.103:9080 {
        header_up Host {upstream_hostport}
        transport http {
            proxy_protocol v2
        }
    }
}

http://192.168.100.103:9080 {
    respond "{http.request.remote.host}" 200
}

And curl command will output the same response;

$ curl -k https://localhost --interface 127.0.0.1
127.0.0.1
$ curl -k https://localhost --interface ::1
::1

Assistance Disclosure

No AI was used.

@francislavoie francislavoie changed the title reverse proxy: do not disable keepalive if proxy protocol is used reverseproxy: do not disable keepalive if proxy protocol is used Oct 16, 2025
@francislavoie francislavoie added this to the v2.11.0 milestone Oct 16, 2025
@francislavoie francislavoie added the feature ⚙️ New feature or request label Oct 16, 2025
Copy link
Member

@francislavoie francislavoie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! Nice little improvement to an edgecase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants