Issue with caddy v2 and Wordpress

1. Caddy version (caddy version):

V2.2.1

2. How I run Caddy:

Caddy run

a. System environment:

macOS Catalina

b. Command:

Caddy run

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:


www.fuzavue.com, fuzavue.com {
root * /Applications/MAMP/htdocs/fuzavue
encode gzip
  log {
    output file /Users/glen/var/log/caddy/fuzavue.log
  }
#push {
#}
     php_fastcgi / 127.0.0.1:9000
file_server
}

3. The problem I’m having:

Website only loads static home page. All over pages just load a white screen

4. Error messages and/or full log output:

Not seeing any errors, but here’s the log for the homepage

Homepage:

{"request": {"remote_addr": "66.235.50.186:49314", "proto": "HTTP/2.0", "method": "GET", "host": "fuzavue.com", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Mobile/15E148 Safari/604.1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Language": ["en-us"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "fuzavue.com"}}, "common_log": "66.235.50.186 - - [03/Nov/2020:20:12:17 -0800] \"GET / HTTP/2.0\" 200 31198", "duration": 0.010460012, "size": 31198, "status": 200, "resp_headers": {"Content-Type": ["text/html; charset=UTF-8"], "X-Wp-Cf-Super-Cache": ["cache"], "X-Wp-Cf-Super-Cache-Active": ["1"], "X-Powered-By": ["PHP/7.4.11"], "Link": ["<https://fuzavue.com/index.php/wp-json/>; rel=\"https://api.w.org/\""], "X-Wp-Cf-Super-Cache-Cache-Control": ["s-max-age=604800, s-maxage=604800, max-age=60"], "Content-Encoding": ["gzip"], "Server": ["Caddy"], "Hummingbird-Cache": ["Served"], "Vary": ["Accept-Encoding, Cookie", "Accept-Encoding"], "Cache-Control": ["s-max-age=604800, s-maxage=604800, max-age=60"]}}

———————/-//////———

Log for example page (not homepage)

handled request {“request”: {“remote_addr”: “66.235.50.186:49302”, “proto”: “HTTP/2.0”, “method”: “GET”, “host”: “fuzavue.com”, “uri”: “/index.php/about-the-fuzavue/”, “headers”: {“User-Agent”: [“Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Mobile/15E148 Safari/604.1”], “Accept-Language”: [“en-us”], “Referer”: [“https://fuzavue.com/”], “Accept”: [“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”], “Accept-Encoding”: [“gzip, deflate, br”]}, “tls”: {“resumed”: false, “version”: 772, “cipher_suite”: 4865, “proto”: “h2”, “proto_mutual”: true, “server_name”: “fuzavue.com”}}, “common_log”: “66.235.50.186 - - [03/Nov/2020:20:10:42 -0800] “GET /index.php/about-the-fuzavue/ HTTP/2.0” 404 0”, “duration”: 0.000266074, “size”: 0, “status”: 404, “resp_headers”: {“Server”: [“Caddy”]}}

5. What I already tried:

It used to work before I converted to caddy v2. I used to have this code in my v1 caddyfile. Not sure if it’s related to this:

rewrite / {
to /index.php?q={query}

6. Links to relevant resources:

It also appears that if I try to manually go to a page (like site/wp-login.php) it displays the actual PHP script instead of the actual page.

This post can be closed, finally figured it out. This is the updated caddyfile I had to use to get wordpress working again with caddy v2

www.fuzavue.com, fuzavue.com {

root * /Applications/MAMP/htdocs/fuzavue
encode gzip
log {
output file /Users/glen/var/log/caddy/fuzavue.log
}
#push {
#}
php_fastcgi / 127.0.0.1:9000
file_server

route {
# Add trailing slash for directory requests
@canonicalPath {
file {
try_files {path}/index.php
}
not path */
}
redir @canonicalPath {path}/ 308

# If the requested file does not exist, try index files
@indexFiles {
	file {
		try_files {path} {path}/index.php index.php
		split_path .php
	}
}
rewrite @indexFiles {http.matchers.file.relative}

@phpFiles {
	path *.php
}
reverse_proxy @phpFiles 127.0.0.1:9000 {
	transport fastcgi {
		split .php
	}

}
}
}

I think you literally just need to remove the needless / character in your original config. No need for that mess.

1 Like

Also, please use ``` on the lines immediately before and after your config to use code formatting. It’s hard to read as-is. And also, please use the caddy fmt command to fix for formatting of your Caddyfile :slightly_smiling_face:

As Matt said, it’s just the /. In Caddy v2, path matching is exact, so you’re basically telling Caddy “only serve PHP on requests to exactly / but nothing else”. Omitting the / is the same as * meaning “match all requests”. Please read about request matchers here:

Are you guys saying to change

php_fastcgi / 127.0.0.1:9000

To

php_fastcgi * 127.0.0.1:9000

Yes, you can even do php_fastcgi 127.0.0.1:9000 because * is optional as long as the next param does not start with /

1 Like

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