1. My Caddy version (caddy -version
):
v2.0.0-beta10 h1:MkLEoR4kj30H90sZ4YBg9O7sd4Zrl77H0m3mW9gyEmE=
2. How I run Caddy:
a. System environment:
Ubuntu 18.04
b. Command:
Following the caddy/dist/init/linux-systemd guide
sudo cp /path/to/caddy /usr/local/bin
sudo chown root:root /usr/local/bin/caddy
sudo chmod 755 /usr/local/bin/caddy
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
sudo groupadd -g 33 www-data
sudo useradd \
-g www-data --no-user-group \
--home-dir /var/www --no-create-home \
--shell /usr/sbin/nologin \
--system --uid 33 www-data
sudo mkdir /etc/caddy
sudo chown -R root:root /etc/caddy
sudo mkdir /etc/ssl/caddy
sudo chown -R root:www-data /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
sudo touch /etc/caddy/Caddyfile
sudo chown root:root /etc/caddy/Caddyfile
sudo chmod 644 /etc/caddy/Caddyfile
sudo mkdir /var/www
sudo chown www-data:www-data /var/www
c. Service file:
[Unit]
Description=Caddy v2
Documentation=https://github.com/caddyserver/caddy/wiki/v2:-Documentation
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
Restart=on-abnormal
User=www-data
Group=www-data
Environment=CADDYPATH=/etc/ssl/caddy
ExecStart=/usr/local/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=4096
[Install]
WantedBy=multi-user.target
d. My Caddyfile:
note.craigary.net {
root * /var/www/note
encode gzip
php_fastcgi unix//run/php/php7.3-fpm.sock
file_server
tls i@craigary.net
}
3. The problem I’m having:
PHP Server doesn’t work, return 502 error.
4. Error messages from systemctl status caddy
:
no such file or directory error:
Nov 30 15:32:22 craigary.net caddy[831]: 2019/11/30 15:32:22.571 ERROR http.log.error dialing backend: dial unix /run/php/php7.3-fpm.sock:0: connect: no such file or directory
5. What I already tried:
- Make sure
/run/php/php7.3-fpm.sock
exists. - Edit caddyfile
php_fastcgi php-fpm:9000
, no error show up in service status, but still 502 error. - Check PHP-FPM www.conf: user / group is www-data, same user as the one running caddy:
[www]
user = www-data
group = www-data
listen = /run/php/php7.3-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3