架构nginx常见错误总结

1、Linux或windows #使用域名

hosts(linux或windows) 没有解析

 
[root@web01 /etc/nginx]# curl blog.oldboy.com
 <a href="https://www.afternic.com/forsale/blog.oldboy.com?utm_source=TDFS_
DASLNC&utm_medium=DASLNC&utm_campaign=TDFS_DASLNC&traffic_type=TDFS_DASLNC&traffic_id=daslnc&">Found</a>.

2、Connection refused #连接拒绝

检查nginx服务是否启动,systemctl status nginx

 root@web01 /etc/nginx]# curl www.oldboy.com
 curl: (7) Failed connect to www.oldboy.com:80; Connection refused

3、Address already in use #nginx正在运行中

 [root@web01 ~]# nginx
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 nginx: [emerg] still could not bind()

4、journalctl -xe

启动或重启nginx 的报错

 [root@web-204 html]# systemctl start nginx
 Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

解决: 1>直接在命令行journalctl -xe查看详细的错误提示 2>用nginx -t 检查语法是否错误

 [root@web-204 html]# nginx -t
 nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:49
 nginx: configuration file /etc/nginx/nginx.conf test failed
 }不成对 

5、configuration file /etc/nginx/nginx.conf test failed

server_name 这一行 没有以 ";" 结尾 terminated 结束

 [root@wed01 ~]# nginx -t
 nginx: [emerg] directive "server_name" is not terminated by ";" in /etc/nginx/nginx.conf:43
 nginx: configuration file /etc/nginx/nginx.conf test failed

6、403 Forbidden #被拒绝

1>网站首页的权限拒绝 2>网站首页不存在(默认找首页文件)

 [root@web01 /usr/share/nginx/html/blog]# curl blog.oldboy.com
 <html>
 <head><title>403 Forbidden</title></head>
 <body>
 <center><h1>403 Forbidden</h1></center>
 <hr><center>nginx/1.16.0</center>
 </body>
 </html>

7、404 Not Found #请求的资源不存在

站点目录下没有aaa.html这个文件

 [root@web01 /usr/share/nginx/html/www]# curl www.oldboy.com/aaa.html
 <html>
 <head><title>404 Not Found</title></head>
 <body>
 <center><h1>404 Not Found</h1></center>
 <hr><center>nginx/1.16.0</center>
 </body>
 </html>

8、Cannot assign requested address #无法分配指定的ip地址

本地没有10.0.0.9这个ip

 [root@web01 /etc/nginx]# nginx -t 
 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
 nginx: [emerg] bind() to 10.0.0.9:80 failed (99: Cannot assign requested address)
 nginx: configuration file /etc/nginx/nginx.conf test failed

解决:ip addr add 10.0.0.9/24 dev eth0 label eth0:1

9、conflicting server name #域名冲突

有两个几个 虚拟主机的域名相同了

 [root 12:27:17 @web01 conf.d]# nginx -t
 nginx: [warn] conflicting server name "www.oldboy.com" on 0.0.0.0:80, ignored
 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
 nginx: configuration file /etc/nginx/nginx.conf test is successful

解决:用grep检索查询server标签文件中存在www.oldboy.com的文件,有多个将其中1一个注释或改名

10、File not found 找不到文件

1>检查nginx的配置是否有误 2>当后缀为php时,给秘书php-fpm没有指定站点目录

 [root@web01 /etc/nginx/conf.d]# curl www.new1983.com/info.php
 File not found.

11、journalctl -xe

 [root@web01 /etc/php-fpm.d]# systemctl restart php-fpm.service 
 Job for php-fpm.service failed because the control process exited with error code. See "systemctl status php-fpm.service" and "journalctl -xe" for details.
 [root@web01 /etc/php-fpm.d]# 

12、502 Bad Gateway

测试nginx与php是否联通时,出现的这个错 原因: 1>php-fpm.service服务没有启动,启动或重启即可

13、Can’t select database 不能选择数据库

在系统中没有创建数据库

16955089-6ea8e1af61affad4.png

13、Error establishing a database connection #建立数据库连接时出错

1>站点目录连接数据库的账号、密码错误

14、user nginx is currently used by process 7259 #用户nginx当前由进程7259使用

删除nginx用户时,提示该用户正在被7259进程使用

 [root@web02 ~]# userdel nginx
 userdel: user nginx is currently used by process 7259
解决:先停止使用该用户的服务systemctl stop nginx php-fpm.service,再删除

15、401 Authorization Required

需要授权的意思,一般是认证失败(用户名和密码)

16、500 Internal Server Error

内部服务器错误或程序错误

17、No route to host #无法到达主机

原因: 1>防火墙、SELinux 2>是否能连接到虚拟机(失联)

posted @ 2021-03-01 21:57  上善若水~小辉  阅读(1908)  评论(0编辑  收藏  举报