我在 Nginx 和 php8.1-fpm 上有多个虚拟主机,每个虚拟主机都有唯一的域名、用户和根目录。
包含/etc/php/8.1/fpm/pool.d/domain.com.conf
user = domainuser
group = domainuser
listen = /var/run/php/php8.1-domain.com-fpm.sock
虚拟主机文件/etc/nginx/sites-available/domain.com.vhost
server {
listen 80;
listen [::]:80;
root /var/www/domain.com;
index index.php index.html index.htm;
server_name domain.com www.domain.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.1-domain.com-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /var/log/nginx/domain.com.access.log;
error_log /var/log/nginx/domain.com.error.log;
}
当我运行时ls -l /var/run/php
,它只显示一个套接字文件,而其他 5 个都丢失了。
srw-rw---- 1 www-data www-data 0 Oct 29 12:48 php8.1-domain.com-fpm.sock
错误日志:
2023/10/29 12:56:50 [crit] 627#627: *3 connect() to unix:/var/run/php/php8.1-domain.com-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 20.163.15.11, server: domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.1-domain.com-fpm.sock:", host: "domain.com"
每个虚拟主机都有唯一的用户、组、套接字位置和根目录。所有用户都添加到 www-data 组中。
答案1
您需要将每个站点放入其自己的池中,否则配置文件会相互覆盖。
[Site1]
user = domainuser
group = domainuser
listen = /var/run/php/php8.1-domain.com-fpm.sock