Caddy -> Apache reverse proxy trailing slash failure

1. Caddy version (caddy version):

v2.4.3

2. How I run Caddy:

Caddy is being used as a reverse-proxy. Apache is listening on port 88.

a. System environment:

CentOS 7, systemd

b. Command:

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

cloud.site.com:443 {
    encode gzip
    log {
        output file /var/log/caddy-access.log
        format json
    }
    tls /root/.acme.sh/cloud.site.com/fullchain.cer /root/.acme.sh/cloud.site.com/cloud.servutech.com.key
    reverse_proxy /v2ray localhost:9999
    #reverse_proxy https://www.bing.com {
    reverse_proxy 127.0.0.1:88 {
        header_up Host {http.reverse_proxy.upstream.hostport}
        header_up X-Real-IP {http.request.remote}
        header_up X-Forwarded-For {http.request.remote}
        header_up X-Forwarded-Port {http.request.port}
        header_up X-Forwarded-Proto {http.request.scheme}
    }
}

3. The problem I’m having:

If a user types an address, without a trailing slash, into their browser’s address bar, the hand-off from Caddy to Apache fails. For example: a user types: https://cloud.site.com/folder (without trailing slash). They are redirected to: http://127.0.0.1:88/folder/ and get an unable to connect browser error. Whereas if the user enters https://cloud.site.com/folder/ (with trailing slash) they are taken to that URL.

How do I fix this?

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

This line is harmful in this situation. This is telling Apache that the Host is 127.0.0.1:88.

Please do not use header_up lines you do not understand. None of those are useful in this situation, and those last four are essentially never useful, and often harmful. Caddy sets the appropriate proxy headers automatically.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.