我有一个安装了 nginx 和 php-fpm (7.2) 的 Ubuntu18.04 网络服务器。
共有 6 个池,每个池都有自己的用户和组:
/etc/php/7.2/fpm# grep -r ^user *
php.ini:user_dir =
pool.d/dev3.website.com.conf:user = dev3_app
pool.d/dev1.website.com.conf:user = dev1_app
pool.d/dev4.website.com.conf:user = dev4_app
pool.d/dev6.website.com.conf:user = dev6_app
pool.d/dev5.website.com.conf:user = dev5_app
pool.d/dev2.website.com.conf:user = dev2_app
/etc/php/7.2/fpm# grep -r ^group *
pool.d/dev3.website.com.conf:group = dev3_app
pool.d/dev1.website.com.conf:group = dev1_app
pool.d/dev4.website.com.conf:group = dev4_app
pool.d/dev6.website.com.conf:group = dev6_app
pool.d/dev5.website.com.conf:group = dev5_app
pool.d/dev2.website.com.conf:group = dev2_app
每个站点都运行一个 laravel 应用程序,并将存储目录设为组可写:
/var/www/dev3.website.com# ls -la
total 2236
drwxr-xr-x 20 root dev3_app 4096 Jul 17 21:39 .
drwxr-xr-x 9 root root 4096 Jul 17 21:33 ..
...
drwxrwxr-x 7 root dev3_app 4096 Jul 17 21:29 storage
nginx通过TCP端口连接:
server {
listen 80;
server_name dev3.website.com;
root /var/www/dev3.website.com/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
# include the fastcgi_param setting
include fastcgi_params;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
}
}
通过这种配置我得到
The stream or file "/var/www/dev3.website.com/storage/logs/laravel-2019-07-17.log" could not be opened: failed to open stream: Permission denied
当我在存储目录上运行 chmod a+w 时,它可以起作用。
我还运行了 ps -ef |grep php:
root 2468 1 0 00:53 ? 00:00:05 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
root 11897 10961 0 22:12 pts/0 00:00:00 grep --color=auto php
答案1
我怀疑它以 root 用户身份运行“主进程”,但对于每个池,它以指定用户身份运行“工作进程”。为了使其正常工作,您必须对日志目录进行 chmod 操作,这一事实进一步证实了这一点。
您可以采取的故障排除步骤是让其中一个站点写入一个文件,/tmp/test
然后检查哪个用户拥有该文件。
您还可以编写一个循环,在其中一个池中休眠几分钟,然后运行命令ps -ef | grep php
来查看“主进程”是否已以您期望的用户身份生成一个进程。