Fedora fastcgi 上的 nginx 无法正常工作

0 php nginx fedora centos fastcgi

我在 Fedora Server 22 上运行 nginx 并且 fastcgi 脚本不起作用。

http://panel.minefight.org/ 下输入任何登录数据,它不会加载密码失败或成功站点。其他登录表单也会发生同样的事情。服务器没有重定向用户,我不知道如何解决这个问题。我希望这个例子容易理解。

testpage 说,fastcgi 正在运行并与 nginx 连接。

php-fpm.conf

upstream php-fpm {
    server unix:/run/php-fpm/www.sock;
}
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

错误日志包含以下内容(尝试登录游戏面板时):

    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/"
Run Code Online (Sandbox Code Playgroud)

奇怪的是,它在 apache 下工作。游戏面板论坛中的用户也报告了这一点:“这似乎是重定向和使用 nginx 正确存储会话的问题。”

同样的事情发生在 owncloud 上。尝试登录 owncloud 时的错误日志:

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/"
Run Code Online (Sandbox Code Playgroud)

如果用户使用参数“?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"
Run Code Online (Sandbox Code Playgroud)

Mic*_*ton 5

您遇到的问题是 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"
Run Code Online (Sandbox Code Playgroud)

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

# 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/
Run Code Online (Sandbox Code Playgroud)

但是因为您将 php-fpm 的用户从 更改apachemanagement,所以新用户无法写入该目录。

要解决此问题,您可以更改运行 php-fpm 的用户和组,或者更改/var/lib/php/session. 请注意,如果您选择后者,则每次升级 PHP 时所有权都会恢复(因为它嵌入到 RPM 包中)并且需要再次更正。

我建议你在这个目录上设置一个 ACL,因为这不会被升级所干扰。例如:

setfacl -m u:management:rwx,d:u:management:rwx /var/lib/php/session
Run Code Online (Sandbox Code Playgroud)