Fedora fastcgi 上的 nginx 无法正常工作

Fedora fastcgi 上的 nginx 无法正常工作

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

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

测试页面显示,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;
}

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

    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 下工作。gamepanel 论坛的一位用户也报告了这一点:“这似乎是 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/"

如果用户使用参数“?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"

答案1

您遇到的问题是 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 的用户从 更改apachemanagement,新用户无法写入该目录。

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

我建议您在此目录上设置 ACL,因为它不会受到升级的干扰。例如:

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

相关内容