caddy2与caddy1相比在语法上有一些更新变化,不了解的话,写的caddyfile是无法让服务器跑起来的。
root格式变化
root * /var/www # matcher token: *
root /index.html /var/www # matcher token: /index.html
root @post /var/www # matcher token: @post
php定义
php_fastcgi localhost:9000 php_fastcgi unix//run/php/php7.4-fpm.sock
log格式
log { output file /var/log/access.log } log { output file access.log format single_field common_log }
proxy变为
reverse_proxy localhost:9005
反向代理需加:
{
header_up Host {http.reverse_proxy.upstream.hostport}
附本人实际caddyfile源码供参考:
:80 {
respond * 404 #首页变404
file_server
#php_fastcgi unix//run/php/php7.4-fpm.sock #去掉#变可用
}
site.net, www.site.net {
root * /home/site
encode zstd gzip
tls yourmail@gmail.com
file_server
log {
output file /var/log/site/access.log {
roll_size 1mb
roll_keep 5
roll_keep_for 720h
}
}
reverse_proxy https://whereyouwantto.com {
header_up Host {http.reverse_proxy.upstream.hostport}
}
php_fastcgi unix//run/php/php7.4-fpm.sock
}
请教一下,CADDY按你说的方式配置还是报404错误
php-fpm 的用户也改成了 caddy
php-fpm 运行状态:
root 23948 1 0 08:23 ? 00:00:00 php-fpm: master process (/www/server/php/74/etc/php-fpm.conf)
caddy 23949 23948 0 08:23 ? 00:00:00 php-fpm: pool www
caddy 23950 23948 0 08:23 ? 00:00:00 php-fpm: pool www
caddy 23951 23948 0 08:23 ? 00:00:00 php-fpm: pool www
caddy 23952 23948 0 08:23 ? 00:00:00 php-fpm: pool www
caddy 23953 23948 0 08:23 ? 00:00:00 php-fpm: pool www
caddy 配置
mysite.com:443 {
root * /www/myweb
tls mymail@qq.com
tls {
protocols tls1.2 tls1.3
ciphers TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
}
php_fastcgi unix//tmp/php-cgi-74.sock {
root /www/myweb
split .php
index index.php
}
# rewrite * /index.php
file_server
log {
output file /var/log/caddy/myweb.log
}
应该是caddyfile有问题,可以按下面的:
mysite.com {
root * /www/myweb
tls mymail@qq.com
php_fastcgi unix//tmp/php-cgi-74.sock {
index index.php
file_server
log {
output file /var/log/caddy/myweb.log
}
}
另外请确定php路径正确,php-cgi ?