Fedora FastCGI上的nginx无法正常工作

我正在Fedora服务器22上运行nginx,而fastcgi脚本不能正常工作。

在http://panel.minefight.org/下input任何login数据,它不会加载密码失败或成功的网站。 其他login表单也会发生同样的情况。 服务器没有redirect用户,我不知道如何解决这个问题。 我希望这个例子很容易理解。

testing页面说,fastcgi正在运行,并与nginx连接。

php-fpm.conf

 upstream php-fpm { server unix:/run/php-fpm/www.sock; } 

php.conf

 index index.php index.html index.htm; location ~ \.php$ { try_files $uri =404; fastcgi_intercept_errors on; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass php-fpm; } 

错误日志包含以下内容(当试图logingamepanel时):

  2015/05/30 22:15:57 [error] 1911#0: *1 FastCGI sent in stderr: "PHP message: PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /mnt/ext/web/html/panel/includes/mysql.php on line 39 PHP message: PHP Warning: session_start(): open(/var/lib/php/session/sess_05tmojugo0peqvoevmlnk4ch36, O_RDWR) failed: Permission denied (13) in /mnt/ext/web/html/panel/include.php on line 52" while reading response header from upstream, client: 92.206.106.243, server: panel.minefight.org, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "panel.minefight.org" 2015/05/30 22:15:57 [error] 1911#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open(/var/lib/php/session/sess_05tmojugo0peqvoevmlnk4ch36, O_RDWR) failed: Permission denied (13) in Unknown on line 0 PHP message: PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading upstream, client: 92.206.106.243, server: panel.minefight.org, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "panel.minefight.org" 2015/05/30 22:16:02 [error] 1911#0: *1 FastCGI sent in stderr: "PHP message: PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /mnt/ext/web/html/panel/includes/mysql.php on line 39 PHP message: PHP Warning: session_start(): open(/var/lib/php/session/sess_05tmojugo0peqvoevmlnk4ch36, O_RDWR) failed: Permission denied (13) in /mnt/ext/web/html/panel/include.php on line 52 PHP message: PHP Warning: Unknown: open(/var/lib/php/session/sess_05tmojugo0peqvoevmlnk4ch36, O_RDWR) failed: Permission denied (13) in Unknown on line 0 PHP message: PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading response header from upstream, client: 92.206.106.243, server: panel.minefight.org, request: "POST /loginprocess.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "panel.minefight.org", referrer: "http://panel.minefight.org/" 2015/05/30 22:16:02 [error] 1911#0: *1 FastCGI sent in stderr: "PHP message: PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /mnt/ext/web/html/panel/includes/mysql.php on line 39 PHP message: PHP Warning: session_start(): open(/var/lib/php/session/sess_05tmojugo0peqvoevmlnk4ch36, O_RDWR) failed: Permission denied (13) in /mnt/ext/web/html/panel/include.php on line 52" while reading response header from upstream, client: 92.206.106.243, server: panel.minefight.org, request: "GET /login.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "panel.minefight.org", referrer: "http://panel.minefight.org/" 2015/05/30 22:16:02 [error] 1911#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open(/var/lib/php/session/sess_05tmojugo0peqvoevmlnk4ch36, O_RDWR) failed: Permission denied (13) in Unknown on line 0 PHP message: PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading upstream, client: 92.206.106.243, server: panel.minefight.org, request: "GET /login.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "panel.minefight.org", referrer: "http://panel.minefight.org/" 

奇怪的是,它是在Apache下工作。 游戏平台论坛中的用户也报告了这一点:“这似乎是与nginx正确redirect和存储会话的问题。”

同一件事发生在owncloud。 尝试在owncloud中login时的错误日志:

 2015/05/30 22:24:07 [error] 1953#0: *5 open() "/mnt/ext/web/html/owncloud/index.php/core/js/oc.js" failed (20: Not a directory), client: 92.206.106.243, server: minefight.org, request: "GET /owncloud/index.php/core/js/oc.js?v=daf8b986d2ba29cf78e2efc057a4a442 HTTP/1.1", host: "minefight.org", referrer: "http://minefight.org/owncloud/" 2015/05/30 22:24:07 [error] 1953#0: *5 open() "/mnt/ext/web/html/404.html" failed (2: No such file or directory), client: 92.206.106.243, server: minefight.org, request: "GET /owncloud/index.php/core/js/oc.js?v=daf8b986d2ba29cf78e2efc057a4a442 HTTP/1.1", host: "minefight.org", referrer: "http://minefight.org/owncloud/" 2015/05/30 22:24:14 [error] 1953#0: *4 open() "/mnt/ext/web/html/owncloud/index.php/core/js/oc.js" failed (20: Not a directory), client: 92.206.106.243, server: minefight.org, request: "GET /owncloud/index.php/core/js/oc.js?v=daf8b986d2ba29cf78e2efc057a4a442 HTTP/1.1", host: "minefight.org", referrer: "http://minefight.org/owncloud/" 2015/05/30 22:24:14 [error] 1953#0: *4 open() "/mnt/ext/web/html/404.html" failed (2: No such file or directory), client: 92.206.106.243, server: minefight.org, request: "GET /owncloud/index.php/core/js/oc.js?v=daf8b986d2ba29cf78e2efc057a4a442 HTTP/1.1", host: "minefight.org", referrer: "http://minefight.org/owncloud/" 

如果用户使用参数“?id = 1”访问phpinfo.php站点,则错误日志包含以下内容:

 2015/05/30 22:35:16 [crit] 2036#0: *7 open() "/var/lib/nginx/tmp/fastcgi/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 92.206.106.243, server: minefight.org, request: "GET /phpinfo.php?id=1 HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "minefight.org" 

您遇到的问题是PHP无法写入/var/lib/php/session目录:

 PHP message: PHP Warning: session_start(): open(/var/lib/php/session/sess_05tmojugo0peqvoevmlnk4ch36, O_RDWR) failed: Permission denied (13) in /mnt/ext/web/html/panel/include.php on line 52" while reading response header from upstream, client: 92.206.106.243, server: panel.minefight.org, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "panel.minefight.org" 

如果你看看这个目录的权限,你会发现这样的:

 # ls -Zld /var/lib/php/session/ drwxrwx---. 2 system_u:object_r:httpd_var_run_t:s0 root apache 44 May 15 05:26 /var/lib/php/session/ 

但是因为你把php-fpm的用户从apache改为management ,新用户不能写入这个目录。

要解决这个问题,可以更改php-fpm运行的用户和组,或者更改/var/lib/php/session的所有权。 请注意,如果你使用后者,所有权将在每次升级PHP时都会恢复(因为它被embedded到RPM包中),并且需要再次修正。

我build议你在这个目录上设置一个ACL,因为这不会受到升级的干扰。 例如:

 setfacl -mu:management:rwx,d:u:management:rwx /var/lib/php/session