Php

NGINX + PHP-FPM 權限被拒絕

  • December 11, 2014

我有幾個WordPress網站,都具有相同的配置 - 僅與user和不同domain,但僅針對新創建的虛擬主機獲得 403:

# cat barelef-art.kiev.ua.conf
server {
   server_name barelef-art.kiev.ua;
   access_log /var/log/nginx/barelef-art.kiev.ua-access.log;
   error_log /var/log/nginx/barelef-art.kiev.ua-error.log;
   root /var/www/vhosts/barelef_art/barelef-art.kiev.ua;

   location / {
       index index.php;
   }

   location ~ \.php$ {
       include /etc/nginx/fastcgi_params;
       fastcgi_pass  127.0.0.1:9012;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME /var/www/vhosts/barelef_art/barelef-art.kiev.ua$fastcgi_script_name;
   }
}

還有 - 一些站點的類似 php-fpm 配置:

# cat barelef-art.kiev.ua.conf
[barelef-art.kiev.ua]

listen = 127.0.0.1:9012

listen.allowed_clients = 127.0.0.1

user = barelef_art
group = barelef_art

pm = dynamic
pm.max_children = 20
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_requests = 50

slowlog = /var/log/nginx/barelef-art.kiev.ua-slow.log

;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/nginx/barelef-art.kiev.ua-error.log
php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 128M

; Set session path to a directory owned by process user
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

php_admin_value[session.save_path] = /var/lib/php/session/barelef_art

使用者存在:

# id barelef_art
uid=523(barelef_art) gid=523(barelef_art) groups=523(barelef_art)

並且 virtualhost 目錄具有正確的所有者:

# ls -l /var/www/vhosts/barelef_art/barelef-art.kiev.ua/
total 192
-rw-r--r--  1 barelef_art barelef_art   418 Dec 11 18:59 index.php
-rw-r--r--  1 barelef_art barelef_art 19930 Dec 11 18:59 license.txt
-rw-r--r--  1 barelef_art barelef_art 10691 Dec 11 18:59 readme.html
-rw-r--r--  1 barelef_art barelef_art  4951 Dec 11 18:59 wp-activate.php
...
drwxr-xr-x 12 barelef_art barelef_art  4096 Dec 11 18:59 wp-includes
...

# ls -l /var/lib/php/session/
total 328
drwxr-xr-x 2 barelef_art barelef_art   4096 Dec 11 19:06 barelef_art

但是當我嘗試打開 index.php - 我進入了日誌:

2014/12/11 20:39:18 [error] 13839#0: *133 "/var/www/vhosts/barelef_art/barelef-art.kiev.ua/index.php" is forbidden (13: Permission denied), client: 37.***.***.56, server: barelef-art.kiev.ua, request: "GET / HTTP/1
.1", host: "barelef-art.kiev.ua"

我做錯了什麼?

再一次 - 相同的配置文件用於少數具有相同 CMS 的網站,並且它們可以工作。我今天早上添加了其中一個。晚上 - 添加了這個新的 - 它不起作用……似乎 - 我錯過了一些東西,但是 - 無法理解什麼和在哪裡。

CentOS 6.6,Nginx 1.6.2。

UPD

添加index.html,直接用http://barelef-art.kiev.ua/index.html打開也返回403;

ps為PHP-FPM程序返回正確的使用者:

# ps -eo user:$(cut -d: -f1 /etc/passwd | wc -L),pid,ppid,c,stime,tname,time,cmd | grep "php-fpm.*barelef" | grep -v grep
barelef_art 14883 14868  0 21:33 ?        00:00:00 php-fpm: pool barelef-art.kiev.ua

# lsof -p 14883 | head
COMMAND   PID        USER   FD   TYPE  DEVICE SIZE/OFF    NODE NAME
php-fpm 14883 barelef_art  cwd    DIR   253,0     4096       2 /
php-fpm 14883 barelef_art  rtd    DIR   253,0     4096       2 /
php-fpm 14883 barelef_art  txt    REG   253,0  3309952 1051669 /usr/sbin/php-fpm
php-fpm 14883 barelef_art  mem    REG   253,0    65928 1709260 /lib64/libnss_files-2.12.so
php-fpm 14883 barelef_art  mem    REG   253,0    83088 1179907 /usr/lib64/php/modules/zip.so

但似乎更多的NGINX問題……

檢查目錄/var/www/vhosts/barelef_art/barelef-art.kiev.ua/&的權限/var/www/vhosts/barelef_art/

當在 Nginx 或 Apache 中遇到禁止錯誤時,總是值得以自己的方式備份目錄樹,以確保 Web 伺服器可以在每個級別訪問。

引用自:https://unix.stackexchange.com/questions/173810