【Nginx—故障集合】

* 索引

1.Connection refused Nginx服务没有运行
2.unexpected "}" in /etc/nginx/nginx.conf 配置文件内容语法错误了
3.Linux或windows 使用域名 hosts没有解析域名
4.is not treminated by 没有以...结束
5.404 找不到 站点目录可能没有创建,或者nginx.conf配置文件站点目录写错了
6.403 Forbidden 权限拒绝 权限拒绝(第一种)
7.403 Forbidden 权限拒绝 首页文件不存在(第二种)
8.Cannot assign requested address 无法分配指定请求的ip地址
9.304 Not Modified (提示)用户读取浏览器缓存
10.Address already in use 地址已被使用
11.Connection refused 连接拒绝
12. conflicting server name 服务器名称冲突
13.500 internal Server Error 内部服务器错误
14.Error establishing a database connection 建立数据库连接失败
15.Can't connect to local MySQL server through socket 连接不到本地的数据库

内部服务器错误1.Nginx服务没有运行

80端口没有开
重启nginx服务 systemctl restart nginx

image
[17:10 root@web01 /etc/nginx/conf.d]# curl www.oldboy.com
curl: (7) Failed connect to www.oldboy.com:80; Connection refused
[17:10 root@web01 /etc/nginx/conf.d]# systemctl restart nginx
[17:10 root@web01 /etc/nginx/conf.d]# curl www.oldboy.com
www.oldboy.com

2.查看详细Nginx错误提示 检查语法 nginx -t

一般宝花括号说明配置文件内容语法错误了
"}"不成对

systemctl  
[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.

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

image

3./etc/hosts文件域名没有解析

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

image

4.server_name这行没有以分号结尾 ";"

treminated 结束
 40     server   {
 41         listen       80;
 42         server_name  blog.oldboy.com   \\没有以 ; 结尾
 43         location / {
 44         root   /usr/share/nginx/html/blog;
 45         index  index.html index.htm;
 46         }
 47     }
 48 
 49 }

image

5.报错—404 找不到

站点目录可能没有创建,或者nginx.conf配置文件站点目录写错了
[root@web01 ~]# cat /usr/share/nginx/html/{www,blog}/index.html
www.oldboy.com
blog.oldboy.com
[root@web01 ~]# curl blog.oldboy.com
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>

* * *

<center>nginx/1.16.0</center>
</body>
</html

image

6.报错—403 权限拒绝(第一种)

Forbidden 权限拒绝
image

模拟错误:站点目录权限修改为000 测试完后改回644:

[09:34 root@web01 ~]# ll  /usr/share/nginx/html/www/
total 4
-rw-r--r-- 1 root root 15 Jun  5 09:00 index.html
[09:35 root@web01 ~]# chmod 600 index.html
[09:35 root@web01 ~]#  ls -l index.html 
-rw------- 1 root root 15 Jun  5 09:00 index.html
[09:35 root@web01 ~]# curl www.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.报错—403 首页文件不存在(第二种)

首页文件不存在 默认是找首页文件
image

模拟将站点目录移动到别处:

[16:35 root@web01 ~]# mv /usr/share/nginx/html/www/index.html /tmp/
[16:35 root@web01 ~]# curl www.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>

8. Cannot assign requested address 无法分配指定请求的ip地址

本地没有10.0.0.9 的ip
10.0.0.9:80 (failedCannot assign)

[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

解决方法1:添加1个ip地址:

[root@web01 ~]# ip addr add 10.0.0.9/24 dev eth0 label eth0:1   \\添加此ip

9. 304 Not Modified 用户读取浏览器缓存

/var/log/nginx/access.log日志中显示304

image

10.Address already in use 地址已被使用

nginx已经启动了,在使用80端口
只是提示,不是报错
Address already in use
nginx正在运行中

image

11.Connection refused 连接拒绝

[16:25 root@web01 ~]# curl www.oldboy.com
curl: (7) Failed connect to www.oldboy.com:80; Connection refused
[16:25 root@web01 ~]# systemctl restart nginx
[16:25 root@web01 ~]# curl www.oldboy.com
www.oldboy.com

12. conflicting server name 服务器名称冲突

域名冲突: 有两个或多个 虚拟主机的域名相同了
解决方法:可以将默认 default.conf压缩

 [root 12:27:22 @web01 conf.d]# vim 01-www.conf 

server {
      listen    80;
      server_name     www.oldboy.com;  \\域名重复
      #charset koi8-r;
      access_log  /var/log/nginx/access_www.log  main;

      location / {
          root   /usr/share/nginx/html/www;
          index  index.html index.htm;
                }
     }

[root 12:35:02 @web01 conf.d]# cat default.conf
server {
    listen       80;
    server_name  www.oldboy.com;   \\域名重复
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

[16:52 root@web01 /etc/nginx/conf.d]# gzip  default.conf
[16:52 root@web01 /etc/nginx/conf.d]# ll
total 16
-rw-r--r-- 1 root root 219 Jun  5 12:56 01-www.conf
-rw-r--r-- 1 root root 240 Jun  5 12:55 02-blog.conf
-rw-r--r-- 1 root root 488 Apr 23 22:34 default.conf.gz  \\压缩
-rw-r--r-- 1 root root 123 Jun  5 12:41 status.conf

13.500 internal Server Error

内部服务器错误
设置了权限认证auth_basic_user_file
密码文件权限不对

image

改为600

[09:45 root@web01 /etc/nginx]# chmod 600 htpasswd 
[09:46 root@web01 /etc/nginx]# ll htpasswd 
-rw------- 1 nginx nginx 45 Jun  6 09:30 htpasswd

14.Error establishing a database connection

建立数据库连接失败
搭建好的wordpress博客进不去
修改权限blog站点目录的属主属组为nginx

[root@web01 ~]#  chown  -R nginx.nginx /usr/share/nginx/html/blog/
[root@web01 ~]# ll -d /usr/share/nginx/html/blog/
drwxr-xr-x 5 nginx nginx 4096 Jun  6 21:03 /usr/share/nginx/html/blog/

image

15.Can't connect to local MySQL server through socket

连接不到本地的数据库
数据库服务没有开启

[root@web01 html]# systemctl restart mariadb.service 
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • * 索引 内部服务器错误1.Nginx服务没有运行 80端口没有开重启nginx服务 systemctl rest...
    Linux丶晨星阅读 1,230评论 1 7
  • 《老男孩Linux运维》笔记 隐藏Nginx软件版本号 一般来说,软件的漏洞都和版本有关。因此要尽量隐藏对访问用户...
    Zhang21阅读 3,712评论 0 28
  • ORA-00001: 违反唯一约束条件 (.) 错误说明:当在唯一索引所对应的列上键入重复值时,会触发此异常。 O...
    我想起个好名字阅读 5,455评论 0 9
  • 1、第八章 Samba服务器2、第八章 NFS服务器3、第十章 Linux下DNS服务器配站点,域名解析概念命令:...
    哈熝少主阅读 3,782评论 0 10
  • 1.ngnix介绍 ngnix www服务软件 俄罗斯人开发 开源 性能很高 本身是一款静态WWW软件 静态小文件...
    逗比punk阅读 2,132评论 1 6