
我有一個 Ubuntu18.04 Web 伺服器,安裝了 nginx 和 php-fpm (7.2)。
有 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
命令以查看「主進程」是否按照您期望的使用者方式產生了一個進程。