AltServer 上的 PHP-FPM 和 NGINX:502 错误网关

问题描述 投票:0回答:1

设置 Bookstack 后,出现错误“502 Bad Gateway” 操作系统 - 替代服务器 10 /etc/nginx/sites-avialable.d/bookstack.conf 中的代码: 我取自 Github

的示例
server {
  listen 80;
  listen [::]:80;

  server_name 127.0.0.1;

  root /var/www/bookstack/public;
  index index.php index.html;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
  
  location ~ \.php$ {
    include fastcgi.conf;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
  }
}

来自 /var/www/bookstack/.env 的代码:

APP_URL=http://127.0.0.1

# Database details
DB_HOST=localhost
DB_DATABASE=bookstack
DB_USERNAME=bookstack
DB_PASSWORD=bookstack

# Mail system to use
# Can be 'smtp' or 'sendmail'
MAIL_DRIVER=smtp

# Mail sender details
MAIL_FROM_NAME="BookStack"
[email protected]

# SMTP mail options
# These settings can be checked using the "Send a Test Email"
# feature found in the "Settings > Maintenance" area of the system.
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

来自 /var/log/nginx/error.log 的代码:

2023/04/27 02:59:57 [crit] 20019#20019: *1 connect() to unix:/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.2-fpm.sock:", host: "127.0.0.1"

但是在 /run/php/ 中我没有该文件。我的 /run 中也没有文件夹 php 。 如果我删除的话

  location ~ \.php$ {
    include fastcgi.conf;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
  }

来自/etc/nginx/sites-avialable.d/bookstack.conf,我有同样的错误,但刷新页面后下载了一些txt文件。

我为书库重新制作数据库,为她重新制作用户和权限。 在网上查了很多解决方案,但没有一个适合我的情况。 我期望至少有正确的方向,我可以找到更多。

database nginx mariadb nginx-config
1个回答
0
投票

让我尝试向您解释您正在尝试执行的操作的核心概念,以便您下次能够自己正确配置它。

首先,我从未听说过“AltServer10”,这使得您不太容易遵循如何使用 NGINX 和 PHP-FPM 设置应用程序堆栈的一般教程。但我为您做了一些研究。

PHP FPM

首先确保您已经安装了 PHP-FPM。这是包定义: https://packages.altlinux.org/en/p10/srpms/php8.1-fpm-fcgi/

我不知道 oackage 管理器 AltServer 使用的是什么...所以你应该看看这个。

安装 FPM 后,您必须配置 FPM PHP 工作池。

在 Ubuntu、RHEL、CentOS 上,配置文件将位于

/etc/php/7.3/fpm/pool.d
中并命名为
www.conf
。如果您使用其他软件包,配置路径可能会有所不同。雷米将指出 ``

我总是更改我的设置来映射 NGINX 的运行用户,如下所示。请注意,这不是完整的

www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php80-fpm.sock

; Set listen(2) backlog.
; Default Value: 511
;listen.backlog = 511

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
;                 mode is set to 0660
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

listen
配置很重要。它告诉 FPM 将套接字放在哪里(在本例中),我们可以将请求(来自 NGINX)发送到。

这必须与您的 nginx 配置匹配。但首先让我们创建/启动 FPM 服务。再次,不知道如何在 AltServer 上执行此操作,但如果 Alt 使用

systemd
systemctl
,你可以执行类似的操作
/bin/systemctl start php8-fpm.service

我研究了 AltServer FPM 包,该服务很可能会这样命名。看这里:https://packages.altlinux.org/en/p10/srpms/php8.1-fpm-fcgi/specfiles/

好的,现在您应该已经启动并运行了 FPM 服务。请检查运行目录。它应该有一个

sock
文件,例如
/var/run/php80-fpm.sock

NGINX

我的 NGINX PHP 看起来像

location ~ \.php$ {
            fastcgi_pass unix:/var/run/php80-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

请检查您的

fastcgi.conf
中有什么。它应该包括上面列出的一些
fcgi
指令。

这足以使您的 PHP 应用程序正常运行。在 DigitalOcean 上可以找到一个非常好的教程:https://www.digitalocean.com/community/tutorials/php-fpm-nginx

它涵盖了 Ubuntu,但你应该能够适应它。

使用 PHP-FPM 的 NGINX 替代方案是 NGINX Unit。

也可在 AltServer 上使用:https://packages.altlinux.org/en/p10/srpms/unit/

确保您正在安装 Unit + PHP 语言模块

unit-php
。 看这里:https://packages.altlinux.org/en/p10/binary/unit-php/x86_64/

配置将变得更加容易,因为您唯一需要做的就是创建单元配置并应用它。这里描述:

http://unit.nginx.org/configuration/#php

© www.soinside.com 2019 - 2024. All rights reserved.