• Hello,

    I recently moved my WordPress Multisite to a new provider. I’m running WordPress using a Docker container with Caddy as a reverse proxy (for SSL).

    df83e048e8b2   caddy:2-alpine           "caddy run --config …"   23 hours ago   Up 23 hours   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 2019/tcp   caddy
    5f3bc6765cfa   wordpress:5.8.2-apache   "docker-entrypoint.s…"   23 hours ago   Up 23 hours   0.0.0.0:8081->80/tcp                                 wordpress
    7dce1a66b0fb   mysql:5.7                "docker-entrypoint.s…"   23 hours ago   Up 23 hours   3306/tcp, 33060/tcp                                  wordpress-mysql

    My relevant Caddy config is below (I’m using this Caddy container for a Dokuwiki site as well with no problems):

    {
      email [email protected]
      acme_ca https://acme-v02.api.letsencrypt.org/directory
    }
    wp.shand.net, adam.nz {
      reverse_proxy wordpress:80 {
      }
    }

    I copied the old WordPress files across to the new setup and restored the MySQL database and things are mostly working.

    The DOMAIN_CURRENT_SITE is wp.shand.netand the site I’m trying to get to work is adam.nz.

    The problem I’m having is that:

    If I use https://adam.nz as the “Site Address,” the site works but I get SSL errors. I believe this is because Caddy automatically forwards to https but the HTML generated by WordPress has all the images and CSS files with http links.

    ? http adam.nz
    HTTP/1.1 308 Permanent Redirect
    Connection: close
    Content-Length: 0
    Date: Thu, 30 Dec 2021 06:56:25 GMT
    Location: https://adam.nz/
    Server: Caddy
    
    ? https adam.nz | egrep "adam.nz.*.css" | head
    <link rel='stylesheet' id='ugb-style-css-css'  href='https://adam.nz/wp-content/plugins/stackable-ultimate-gutenberg-blocks/dist/frontend_blocks.css?ver=2.17.5' type='text/css' media='all' />
    <link rel='stylesheet' id='block-gallery-frontend-css'  href='https://adam.nz/wp-content/plugins/block-gallery/dist/blocks.style.build.css?ver=1.1.6' type='text/css' media='all' />
    

    If I use https://adam.nz as the “Site Address,” I get infinite redirects.

    ? https -f adam.nz
    HTTP/1.1 301 Moved Permanently
    Cache-Control: max-age=3600
    Content-Length: 0
    Content-Type: text/html; charset=UTF-8
    Date: Thu, 30 Dec 2021 07:01:01 GMT
    Expires: Thu, 30 Dec 2021 08:01:02 GMT
    Location: https://adam.nz/
    Server: Caddy, Apache/2.4.51 (Debian)
    X-Powered-By: PHP/7.4.27
    X-Redirect-By: redirection
    
    ? https -F adam.nz
    https: error: Too many redirects (--max-redirects=30).

    I can’t figure out why I’m getting infinite redirects when I enable https in the “Site Address” and I’m not sure how to debug this.

    Many thanks for any help.
    Adam.

    • This topic was modified 3 years, 2 months ago by adamshand.
    • This topic was modified 3 years, 2 months ago by adamshand.
    • This topic was modified 3 years, 2 months ago by adamshand.
    • This topic was modified 3 years, 2 months ago by adamshand.
    • This topic was modified 3 years, 2 months ago by adamshand.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Try using your browser’s network developer tool. It’ll normally log redirects, but I don’t think it’ll log internal redirects behind a reverse proxy. Worth checking just in case it offers any clues.

    You can set trace levels in Apache’s configuration file, which are recorded in the access log. This will log internal server rewrites, but again I don’t think it’ll log proxy activity.

    I’d expect the proxy to have its own trace logging scheme but that’s outside of my knowledge base.

    My best guess to the cause is there’s an inadvertent HTTP URL in the redirect chain so the request infinitely bounces back and forth between HTTP and HTTPS.

    Thread Starter adamshand

    (@adamshand)

    Thanks for the suggestions, will do some more experimenting.

    Thread Starter adamshand

    (@adamshand)

    Okay it appears to just be caught in a loop. If I go to https://adam.nz WordPress gives the browser a 301 redirect tohttps://adam.nz.

    It’s like Multisite thinks that the “Site Address” doesn’t match the URL, even when it does and so it redirects the client endlessly.

    I’m assuming that this is something to do with the reverse proxy setup, that the URL is getting lost as it’s passed through to WordPress. I tried updating my Caddy config to:

    wp.shand.net, adam.nz {
      reverse_proxy wordpress:80 {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
      }
    }

    But it completely breaks if I do that. I’m starting to suspect that this is a Caddy problem not a WordPress problem.

    • This reply was modified 3 years, 2 months ago by adamshand.
    Thread Starter adamshand

    (@adamshand)

    Okay I think I’ve figured this out. Documenting in case it’s helpful to some poor future soul.

    Once I followed the instructions in this post and added the below snippet to my wp-config.php, everything started working.

    
    if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {?
    $_SERVER['HTTPS'] = 'on';?
    }
    

    With this snippet it no longer matters whether the “Site Address” is set to http or https, it just works.

    It seems like this shouldn’t be required and this should be fixable by making sure that the headers are getting passed through correctly. But I couldn’t figure out any combination of headers that made WP behave as I expected.

    • This reply was modified 3 years, 2 months ago by adamshand.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Moving WP Multisite – getting infinite redirects’ is closed to new replies.