Caddy and Wordpress

Note sure exactly what is going on here but I am trying to setup wordpress on my root domain. Caddy is on one docker host while wordpress is on another…

Caddyfile:

www.domain.net, domain.net {
        gzip
        index index.hmtl index.htm
        tls certs@domain.net
        header / {
          Content-Security-Policy
          default-src "*"
          X-Frame-Options "DENY"
          X-Content-Type-Options "nosniff"
          X-XSS-Protection "1; mode=block"
          Strict-Transport-Security "max-age=31536000;"
          Referrer-Policy "same-origin"
        }
#       rewrite {
#         if {path} is /home
#         to /external
#       }
#       redir /external https://test.net
        proxy / http://10.9.9.52 {
                header_upstream Host {host}
                header_upstream X-Real-IP {remote}
                header_upstream X-Forwarded-For {remote}
                header_upstream X-Forwarded-Proto {scheme}
        }
#       rewrite {
#               r /uploads\/(.*)\.php
#               to /
#       }
#       rewrite {
#               if {path} not_match ^\/wp-admin
#               to {path} {path}/ /index.php?{query}
#       }
        proxy /portainer/ 10.9.9.52:9000 {
                without /portainer
                transparent
                header_upstream -Connection
        }
        proxy /portainer/api/websocket/ 10.9.9.52:9000 {
                without /portainer
                transparent
                websocket
        }
        proxy /ombi 10.9.9.132:3579 {
                transparent
        }
        proxy /grafana/ http://10.9.9.132:3000 {
                without /grafana/
                transparent
                websocket
        }
        redir /donate https://domain.net 302
        log stdout
}

Error:

I type: domain.net and then url bar goes:

https://domain.net/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/

and chrome goes:

ERR_TOO_MANY_REDIRECTS

lol?

Also I tried just passing transparent and that didn’t work either.

I have also tried setting wordpress site and home page url to my root domain as well as editing the wp-config.php to check for reverse proxy headers…

Proxying to 10.9.9.52/index.php as your upstream probably has something to do with it…

Simplify it down. Try a simple proxy / 10.9.9.52 and see if that works.

P.S. index is unnecessary if every path is going to be proxied.

I tried both ways. Neither seemed to work.

Just checking to confirm that:

www.example.com, example.com {
  tls certs@domain.net
  proxy / 10.9.9.52
}

Isn’t working? Does it produce the same problem (infinite redirection)?

Yup. That way also produces the redirect issue.

Alright, I think we may have to troubleshoot the upstream itself, then.

Can you give us the output of curl -IL https://www.example.com as well as curl -IL 10.9.9.52 from the Caddy host?

If they redirect a lot, feel free to post the whole chain anyway (it’ll put a scroll bar down inside the preformatted block).

OK well apparently I am dumb. The IP should have actually been 10.9.9.132. Which I fixed but now its failing to load any resources and instead just loads a basic html page with no formatting.

Failed to load resource: net::ERR_CONNECTION_TIMED_OUT

New Caddyfile:

www.alexsguardian.net, alexsguardian.net {
        gzip
        tls certs@alexsguardian.net
        header / {
          Content-Security-Policy
          default-src "*"
          X-Frame-Options "DENY"
          X-Content-Type-Options "nosniff"
          X-XSS-Protection "1; mode=block"
          Strict-Transport-Security "max-age=31536000;"
          Referrer-Policy "same-origin"
        }
#       rewrite {
#         if {path} is /home
#         to /external
#       }
#       redir /external test.com
        proxy / http://10.9.9.132 {
                header_upstream Host {host}
                header_upstream X-Real-IP {remote}
                header_upstream X-Forwarded-For {remote}
                header_upstream X-Forwarded-Proto {scheme}
        }
}

also removing the http:// results in this:

GET https://10.9.9.132/wp-content/themes/twentynineteen/print.css?ver=1.2 net::ERR_NETWORK_CHANGED
alex@pc:~$ curl -Il https://www.alexsguardian.net
HTTP/1.1 301 Moved Permanently
Date: Mon, 18 Feb 2019 14:30:43 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=d40a281428ea3115af16b507467cba1861550500243; expires=Tue, 18-Feb-20 14:30:43 GMT; path=/; domain=.alexsguardian.net; HttpOnly
Location: https://alexsguardian.net/
Server: cloudflare
CF-RAY: 4ab13178f8fb578f-IAD
alexander@andromeda:~$ curl -Il 10.9.9.132
HTTP/1.1 200 OK
Date: Mon, 18 Feb 2019 14:21:50 GMT
Server: Apache/2.4.25 (Debian)
X-Powered-By: PHP/7.2.15
Link: <http://10.9.9.132/wp-json/>; rel="https://api.w.org/"
Content-Type: text/html; charset=UTF-8

Fixed it.

re-added

define( 'WP_HOME', 'http://alexsguardian.net' );
define( 'WP_SITEURL', 'http://alexsguardian.net' );

to wp-config.php and restarted wordpress. Now it works.

1 Like

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