Caddy works properly with PHP7.1-FPM? All PHP requests works, /wp-admin also. But, all requests for themes or plugins area returns a “Bad Gateway”. I have to alternate to NGINX (mainline, indeed) and works like a charm, not into Caddy.
Ok, I’ve checked Github issues and googled, tho. But I do not know how to fix it. Suggestions?
I’d probably do the Caddyfile a little differently. This should be faster than using regex, and I think more readable. The php preset at the end of the fastcgi directive also makes the ext, split, and index subdirectives redundant.
fastcgi / /var/run/php/php7.1-fpm.sock php
rewrite {
if {path} not_starts_with /wp-content
if {path} not_starts_with /wp-admin
if {path} not_starts_with /wp-includes
to {path} {path}/ /index.php
}
That said, either approach is equivalent to the Apache recommendation. It seems unlikely that the issue is with the Caddyfile.
A 502 error means that Caddy received an inappropriate response from upstream. A 504 means a timeout. The upstream in this case is /var/run/php/php7.1-fpm.sock.
It could be an issue with php7.1-fpm, or perhaps with /wp-admin/network/index.php. It may even be an issue with Caddy’s fastcgi. You might try changing PHP verisons, trying FastCGI over a port instead of unix socket, or redownloading WordPress.
Thank you very much about your feedback.
In fact, 502 means a inappropriate response from upstream and 504 a timeout.
I"ve been changed my Caddyfile. Assuming a WordPress multisite and multidomain
rewrite {
if {path} not_match ^\/wp-admin
to {path} {path}/ {path}/index.php /index.php/{uri_escaped}
}
rewrite {
r ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)
to ${2}
}
rewrite {
if {path} not_match ^\/wp-admin
r ^([_0-9a-zA-Z-]+/)?(.*\.php)$
to ${2}
}
For now, works like a charm. Anyway, I’ve still 3 problems.
1. I’d like a global redirect
assuming all sites will not work with 80, only HTTPS, no-www
* www to non-www - PENDING
* 80 to 443 - SOLVED
2. Resolv and bind both => IPv4 and IPv6
Yeah, I’ve checked Github Issues: #864 at Caddy Server already and #9334 at Golang
a. if possible
* how to bind?
* bind domain?
* bind address only?
b. if not possible
* Can I use NGINX to proxy with Caddy?
* NGINX with 80 and 443 port => Caddy with another port?
* How to use the same certificate automatically created by Caddy?
3. Remove /index.php/ from permalinks into WordPress
Assuming the Domain.com actually I know… I can use only %postname% as permalink
* Using NGINX, I do not have this /index.php/, what happens? Why?
* Is it abnormal behavior? How to remove it from path structure?
Specifying both http and https labels will help Caddy issue the right redirect the first time for the HTTP request, instead of double bouncing the client by redirecting to HTTPS and then redirecting to canonical.
@Whitestrake, I can use regex into rewrite on Caddy. Ok. Caddy allow a regular expression instead server name - as NGINX? I do not try it yet and I didn’t see something like that on docs.
The closest you’ll get to that behaviour would be, in a default site, selecting for your host in an if statement.
:80, 443 {
redir {
if {host} match [REGEX]
# go somewhere
}
}
The problem is that you can’t get match groups out of it, so it’s not very useful. You’d need to know the hostname you want to go to, without the www, in advance, which is why I made the recommendation above (which only redirects www for the sites you know in advance).
I thought briefly about using rewrite, but you can’t manipulate the host value with that, only the request URI.