Caddy V2 Docker reverse proxy Wordpress

1. My Caddy version (caddy version):

v2.0.0-rc.3

2. How I run Caddy:

Docker using Caddyfile

a. System environment:

Docker

b. Command:

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

d. My complete Caddyfile or JSON config:

mywebsite.domain.ext {
        root * /var/www/html
        reverse_proxy * localhost:2346 {
                header_up Host {http.reverse_proxy.upstream.hostport}
                header_up X-Forwarded-For {http.request.remote}
                header_up X-Real-IP {http.reverse-proxy.upstream.address}
                header_up X-Forwarded-Port {http.reverse_proxy.upstream.port}
                header_up X-Forwarded-Proto {http.request.scheme}
        }
}

3. The problem I’m having:

After mirgrating my Caddyfile from V1, everything is working except wordpress.
I used to use proxy with “transparent” and it worked well.
Now the first page of the wordpress is working fine but when I try to navigate to an other page, I get redirected to “https://localhost/category/europe/”

4. Error messages and/or full log output:

Connexion refused

5. What I already tried:

I tried to use php_fastcgi but it looks like it doesn’t work with reverse proxy

6. Links to relevant resources:

php_fastcgi is used if you don’t have a webserver for your PHP app and you want to use something like php-fpm to execute your PHP code. If you’re running another webserver (apache, nginx, etc) then reverse_proxy is what you should use.

The issue you’re seeing here is that you’re using incorrect placeholders for your header_up subdirectives. You can probably remove all of those entirely and it should work just fine. Caddy automatically passes through the Host, X-Forwarded-For (and will pass throughX-Forwarded-Proto in the current master branch, but not in RC3). For the other two if they’re actually required, you can use the {remote_host} and {http.request.port} placeholders instead.

1 Like

Dang, Francis beat me to it.

Basically, you’re doing way more work than you have to, and breaking your config at the same time.

This should work:

mywebsite.domain.ext

root * /var/www/html
reverse_proxy localhost:2346

Thank you for your response.

The thing is if I remove the :

header_up Host {http.reverse_proxy.upstream.hostport}

I get the error “ERR_TOO_MANY_REDIRECTS”.

WordPress doesn’t like being behind a proxy, from what I’ve heard. I don’t use WordPress, so you’ll have to make sure it’s configured not to redirect like it’s doing.

Are you sure you correctly configured the site address in Wordpress? See How to Fix The ERR_TOO_MANY_REDIRECTS Error

Thank you both for your responses.

The bad redirection was actually due to the target pages… Which were not implemented… My bad !

Actually the header_up were working fine !
If anyone has the same problem here is my working configuration :

mywebsite.domain.ext { 
        reverse_proxy * localhost:2346 {
                header_up X-Forwarded-Port 443
                header_up X-Forwarded-Proto https
        }
}

For more informations for Wordpress and HTTPS : WP behind reverse proxy all content insecure | WordPress.org

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