1. Caddy version (caddy version
):
v2.3.0
2. How I run Caddy:
systemctl start caddy
a. System environment:
Arch Linux - up-to-date, systemd
b. Command:
N/A
c. Service/unit/compose file:
The default Arch Linux caddy.service file, not edited at all.
[Unit]
Description=Caddy web server
Documentation=https://caddyserver.com/docs/
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
StartLimitIntervalSec=14400
StartLimitBurst=10
[Service]
User=caddy
Group=caddy
Environment=XDG_DATA_HOME=/var/lib
Environment=XDG_CONFIG_HOME=/etc
ExecStartPre=/usr/bin/caddy validate --config /etc/caddy/Caddyfile
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
ExecStopPost=/usr/bin/rm -f /run/caddy/admin.socket
# Do not allow the process to be restarted in a tight loop. If the
# process fails to start, something critical needs to be fixed.
Restart=on-abnormal
# Use graceful shutdown with a reasonable timeout
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
# Hardening options
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
DevicePolicy=closed
LockPersonality=true
MemoryAccounting=true
MemoryDenyWriteExecute=true
NoNewPrivileges=true
PrivateDevices=true
PrivateTmp=true
ProcSubset=pid
ProtectClock=true
ProtectControlGroups=true
ProtectHome=true
ProtectHostname=true
ProtectKernelLogs=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectProc=invisible
ProtectSystem=strict
RemoveIPC=true
ReadWritePaths=/var/lib/caddy /var/log/caddy /run/caddy
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
[Install]
WantedBy=multi-user.target
d. My complete Caddyfile or JSON config:
{
admin "unix//run/caddy/admin.socket"
}
http://hoefnix.sys1 {
root * /srv/http
file_server browse
php_fastcgi unix//run/php-fpm/php-fpm.sock
log {
output file /var/log/caddy/access-hoefnix.log
}
}
3. The problem I’m having:
I’m running caddy2 on a development machine called hoefnix.sys1 in an internal network.
The document root has some sub directories. If a sub directory doesn’t contain an index file (.php of .html), then I want to get a directory listing. But when a subdirectory does have and index file, that index file should be returned.
My problem is very similar to this topic:
Struggling with php_fastcgi and browsing a subdirectory
Except in my case there isn’t a specific sub directory for directory listing. The solution in that topic (with “route”) works well when there is a specific directory for listing. But I want to get a directory listing in every directory, except if that directory contains an index (index.php or index.html).
The following Caddyfile does what I want, except that php files aren’t parsed.
http://hoefnix.sys1 {
root * /srv/http
file_server browse
log {
output file /var/log/caddy/access-hoefnix.log
}
}
So how do I combine “file_server browse” and “php_fastcgi”.
4. Error messages and/or full log output:
N/A
5. What I already tried:
When i tried this:
route {
file_server /* browse
php_fastcgi unix//run/php-fpm/php-fpm.sock
file_server
}
Then, logically, php files aren’t parsed anymore.