Caddy wiki reference: Using Caddy to give WordPress its own directory
This was the original instruction for Method I using the expanded form of php_fastcgi.
- After Installing WordPress in the root folder, move everything from the root folder into
subdir. - Add the following snippet to the Caddyfile.
(php_fastcgix) {
route {
# Add trailing slash for directory requests
@canonicalPath {
file {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 {args.0}/index.php
split_path .php
}
rewrite @indexFiles {http.matchers.file.relative}
# Proxy PHP files to the FastCGI responder
@phpFiles path *.php
reverse_proxy @phpFiles {args.1} {
transport fastcgi {
# env SERVER_PORT 80
split .php
}
}
}
}- Update the site block in the Caddyfile and then reload Caddy.
# Rewrite if the requested URI doesn't begin with /subdir/ or is a non-existent file
@subdir {
not path /subdir/*
not file
}
rewrite @subdir /subdir{uri}
# import php_fastcgix /subdir unix//run/php/php7.4-fpm.sock
import php_fastcgix /subdir 127.0.0.1:9000- Log in to WordPress at
mydomain.com/admin
This is the revised instruction:
- After Installing WordPress in the root folder, move everything from the root folder into
subdir. - Update the site block in the Caddyfile and then reload Caddy.
# Rewrite if the requested URI isn't prefixed with the directory /subdir/ or is a non-existent file
@subdir {
not path /subdir/*
not file
}
rewrite @subdir /subdir{uri}
# Proxy requests to PHP-FPM.
# php_fastcgi unix//run/php/php7.4-fpm.sock {
php_fastcgi 127.0.0.1:9000 {
index off
}
try_files {path} {path}/index.php /subdir/index.php- Log in to WordPress at
mydomain.com/admin

Comments