1. My Caddy version (caddy version
):
v2.0.0-beta.14 h1:QX1hRMfTA5sel53o5SuON1ys50at6yuSAnPr56sLeK8=
2. How I run Caddy:
a. System environment:
- Ubuntu 16.04
- systemd 219
- php 7.0
b. Command:
systemctl restart caddy
c. Service/unit/compose file:
[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
; Do not allow the process to be restarted in a tight loop. If the
; process fails to start, something critical needs to be fixed.
StartLimitIntervalSec=14400
StartLimitBurst=10
[Service]
Restart=on-abnormal
; User and group the process will run as.
User=www-data
Group=www-data
; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=/etc/ssl/caddy
; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/usr/local/bin/caddy2 run --config=/etc/caddy/Caddyfile > /var/log/caddy.log
ExecReload=/bin/kill -USR1 $MAINPID
; Use graceful shutdown with a reasonable timeout
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s
; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576
; Unmodified caddy is not expected to use more than that.
LimitNPROC=512
; Use private /tmp and /var/tmp, which are discarded after caddy stops.
PrivateTmp=true
; Use a minimal /dev (May bring additional security if switched to 'true', but it may not work on Raspberry Pi's or other devices, so it has been disabled in this dist.)
PrivateDevices=false
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
ProtectHome=true
; Make /usr, /boot, /etc and possibly some more folders read-only.
ProtectSystem=full
; … except /etc/ssl/caddy, because we want Letsencrypt-certificates there.
; This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
ReadWritePaths=/etc/ssl/caddy
ReadWriteDirectories=/etc/ssl/caddy
; The following additional security directives only work with systemd v229 or later.
; They further restrict privileges that can be gained by caddy. Uncomment if you like.
; Note that you may have to add capabilities required by any plugins in use.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
d. My complete Caddyfile or JSON config:
www.zhangshenjia.com {
redir https://zhangshenjia.com{uri}
}
zhangshenjia.com
{
root * /www/zhangshenjia.com
encode zstd gzip
reverse_proxy /gg localhost:10000
php_fastcgi 127.0.0.1:9000
file_server
}
3. The problem I’m having:
I have a directory name [next] in my webroot, and there is a [index.php] in it. When I visit [/next/] , everything looks right. But when I visit [/next] , the page shows but assets (js and imgs) are failed to load, since the css path become [/css/style.css], but [/next/css/style.css] is expected.
Caddy V2 document said that php_fastcgi will add trailing slash for directory requests ([php_fastcgi (Caddyfile directive) — Caddy Documentation]). But obviously, it doesn’t work in my case.
4. What I already tried:
I search a lot on google and caddy community for hours, but all solutions is for V1 but not V2.
I found this issue [V2: redirect /path to /path/index.php with assets],It seems that this problem had been fixed severals month ago, and merged in 2.0beta2 [v2: php_fastcgi: 301 redirect if path is a directory (add trailing slash at the end) · Issue #2752 · caddyserver/caddy · GitHub]; but why it doesn’t work in 2.0beta14?