升级到 nginx.conf 和 php 后出现的问题

升级到 nginx.conf 和 php 后出现的问题

我刚刚将 AWS 上的 ubunut 服务器从 Ubuntu 16.x 升级到 Ubuntu 20.04.1 LT

我在升级时遇到了一些问题首先t,但我能够克服这些问题。升级后,我无法让 nginx 运行并再次使用我的网站。

查看我的 nginx.conf 和错误后,此行导致错误:

nclude /etc/nginx/sites-enabled/*;

在 sites-enabled 中有一个示例文件以及我实际的网站文件,因此我将其更改为:

include /etc/nginx/sites-enabled/mywebsite.net;

一旦我解决了这个问题,我就能够启动并运行 nginx,但是当我尝试查看我的网站时,出现了 502 错误。

查看日志时,我能够提取以下行:

2020/11/25 15:27:02 [crit] 12327#12327: *1 connect() to unix:/var/run/php/php7.2-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xx.xx.xx, server: www.mywebsite.net, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "www.mywebsite.net"

所以我回到我的/sites-enabled/mywebsite.net文件,我相信这就是问题所在,因为没有指向 php 的正确位置:

location ~ .php$ {
      fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

但是我不确定下一步该做什么才能让它指向 php 的正确位置?

答案1

假设您已经php-fpm安装,它已使用 启动/启用systemctl,并且它正在正常运行/配置为使用套接字,您应该.sock在 中找到一个文件/var/run/php/

ls -lsha /var/run/php

NGINX 根据您的配置通过 连接到 PHP /var/run/php/php7.2-fpm.sock

fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

我假设在升级过程中,您可能已经不再使用php7.2-fpm。您必须确定php-fpm系统上可用的 版本,确保它正在运行,确定套接字的位置,并将正确的套接字提供给 NGINX 配置。

如果您已将系统配置为 7.2,那么我认为在更新中退回到 7.1 是没有意义的。这些文件似乎只是闲置着,但您可以通过查看它们的创建时间来更好地判断。也许php7.2-fpm仍然安装,但实际上并未运行/启用。

systemctl status php-fpm

相关内容