NGINX:连接()到unix:/run/php/php8.1-fpm.sock失败(95:未知错误)

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

我已经尝试了所有这些问题来解决我的问题,但没有任何效果(123)。

这些文件来自运行实时网站的私人存储库。在此站点上工作的其他人可以复制存储库并在本地运行该站点。然而,我当地的环境给我带来了很多问题。主要问题在于为 php-fpm 创建的套接字。

我可以开发的本地网站加载了 95% 的页面。它主要是一个 OpenLayers 地图网站,还有其他与数据连接的更多静态内容。我可以很好地开发网站的地图部分。然而,在 API 部分,存在来自

502 Bad Gateway
nginx/1.18.0 (Ubuntu)
错误,网址为:
http://localhost/api/
。大多数 API 页面都是通过 PHP 运行的,因此使用 php-fpm。以下是我收到的错误类型。 这里是全套环境文件(组合成一个文件)。

错误日志

2024/12/20 19:44:55 [error] 24#24: *1 connect() to unix:/run/php/php8.1-fpm.sock failed (111: Unknown error) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET /api/map_dates/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "localhost", referrer: "http://localhost/us/map2/"
2024/12/20 20:28:05 [crit] 526#526: *4 connect() to unix:/run/php/php8.1-fpm.sock failed (95: Unknown error) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET /api/map_dates/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "localhost", referrer: "http://localhost/us/map2/"

对原始存储库进行的一些更改使 API 页面可以正确加载。这只是其中的几个,其他完全无法加载。

compose.yaml 文件从上面的链接更改。

# Commenting out this line
#- ${WEB_RUNTIME_ROOT_DIR}/sitez/var/run:/var/run
# Changing the entry point
#entrypoint: /bin/sh -c "service nginx start; service memcached start; service php8.1-fpm start;tail -f /dev/null"
entrypoint: /bin/sh -c "mkdir -p /run/php && chown www-data:www-data /run/php && service nginx start && service memcached start && service php8.1-fpm start && tail -f /dev/null"

将此行添加到 Dockerfile

RUN mkdir -p /run/php && chown www-data:www-data /run/php && chmod 0755 /run/php

更改 nginx.conf。 (注释和取消注释错误日志的调试语句)

# Commenting the line below out in the location ~ [^/]\.php(/|$) { here }
# include snippets/fastcgi-php.conf

# Adding these lines into location /api/ { here }
# proxy_pass http://localhost:9000; # Commented out because this did not work 
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

对 www.conf 的最终更改是将侦听和引用移至用户和组上方的套接字,并取消注释

listen.mode = 0660

我正在尝试编辑 API 页面,它只能显示

php_info();
或一个(不是更多)
print('Here');
语句。据我所知,php 没有按应有的方式进行处理。否则,如果没有
print
php_info
,页面将返回 500 错误,就像即使进行了上述更改也无法工作的页面一样。

我也尝试过TCP端口,也没有解决问题。

php docker sockets nginx ubuntu-server
1个回答
0
投票

事实证明,问题出在可以连接数据库的计算机上没有 SSH 连接。此外,对文件唯一需要的更改是在 yaml 文件中保留一行注释掉;入口点不需要改变。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.