在Linux上安装CentOS并配置环境,直到解压PHP源代码,但当出现浏览器错误时的解决方法

假如出现了nginx的错误页面。

e1.JPG

以下是类似的错误,实际上无法启动nginx。

#nginxの再起動
sudo systemctl restart nginx
#このコマンドを使うと以下のようなエラーが発生する。

由于控制进程退出错误代码,nginx.service的工作失败。
请参阅”systemctl status nginx.service”和”journalctl -xe”获取详细信息。

以下是原文的中文翻译:
nginx无法运行是错误的内容。
我被要求确认“systemctl status nginx.service”和“journalctl -xe”的详细信息。

[root@localhost www]# sudo systemctl -l status nginx.service
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 木 2020-08-13 15:42:14 JST; 5s ago
     Docs: http://nginx.org/en/docs/
  Process: 2591 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

 8月 13 15:42:11 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:12 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:12 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:13 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:13 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:14 localhost nginx[2591]: nginx: [emerg] still could not bind()
 8月 13 15:42:14 localhost systemd[1]: nginx.service: control process exited, code=exited status=1
 8月 13 15:42:14 localhost systemd[1]: Failed to start nginx - high performance web server.
 8月 13 15:42:14 localhost systemd[1]: Unit nginx.service entered failed state.
 8月 13 15:42:14 localhost systemd[1]: nginx.service failed.

nginx:[emerg]将绑定到0.0.0.0:80失败(98:地址已被使用)

由于该错误,无法在80端口上执行,因为它已经被使用。
因此需要确认80端口上正在使用的是什么。

以本地方式在中国的中文环境下解释以下命令:sudo lsof -i :80

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   2776 apache    4u  IPv6  25135      0t0  TCP *:http (LISTEN)
httpd   2777 apache    4u  IPv6  25135      0t0  TCP *:http (LISTEN)
httpd   2778 apache    4u  IPv6  25135      0t0  TCP *:http (LISTEN)
httpd   2779 apache    4u  IPv6  25135      0t0  TCP *:http (LISTEN)
httpd   2780 apache    4u  IPv6  25135      0t0  TCP *:http (LISTEN)
httpd   2781 apache    4u  IPv6  25135      0t0  TCP *:http (LISTEN)

我想在nginx上打开,但是apache占用了端口80。因此,我将卸载apache。

请卸载httpd apr apr-util httpd-tools,用以下命令:sudo yum remove -y httpd apr apr-util httpd-tools

#nginxを再起動
sudo systemctl restart nginx

#nginxを自動起動登録
systemctl enable nginx

现在应该可以启动nginx了。

最后,可以使用nginx -t命令来检查nginx配置文件的语法是否正确。

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

如果Nginx启动了但是PHP-FPM不能正常运行的情况下。

e2.JPG
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

首先,查看错误日志并确认、解释原因。

错误日志可以是/var/log/nginx/error.log或/var/log/php-fpm/error.log。

查看/var/log/nginx/error.log文件

2020/08/13 16:26:10 [crit] 2867#2867: *2 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.0.97, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "192.168.168.90"
2020/08/13 16:26:10 [error] 2867#2867: *2 open() "/var/www/html/favicon.ico" failed (2: No such file or directory), client: 192.168.0.97, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.168.90", referrer: "http://~~/"

错误消息说明

“/var/www/html/favicon.ico” 文件无法访问时,无论浏览器能否正常打开,错误将被忽略。

连接到 unix:/var/run/php-fpm/php-fpm.sock 失败
由于无法接收到 Unix socket 文件,出现了错误。通过修改 php-fpm 的配置文件可以解决这个问题。

通常,配置文件位於以下位置,請打開它。

vi /etc/php-fpm.d/www.conf

如果以下的行已经被用分号注释掉了,就把它们删除掉。

这个一般都能打开。