【故障集合】架构阶段web服务错误集合

错误整体记录

Nginx

  1. Connection refused
  2. Address already in use
  3. 启动 或重启nginx 的报错
  4. Linux或windows 使用域名
  5. 404 Not found
  6. 403 Forbidden
  7. Cannot assign requested address
  8. 304 Not modified
  9. conflicting server name
  10. 401 Authorization Required
  11. 500 Internal Server Error
  12. no route to host
  13. Unit is masked.
  14. nginx: [warn] conflicting server name ]

blog.rjclinux.cn" on 0.0.0.0:80, ignored

MySQL错误

ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

一.Nginx错误提示:

1.Connection refused

连接拒绝

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

服务 是否运行

2Address 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()

备注: nginx 可以运行nginx服务

3. 启动 或重启nginx 的报错

查看详细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

4. }不成对 导致故障

5.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&amp;utm_medium=DASLNC&amp;utm_campaign=TDFS_DASLNC&amp;traffic_type=TDFS_DASLNC&amp;traffic_id=daslnc&amp;">Found</a>.

6.nginx: [emerg] directive "server_name" is not terminated by ";" in

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


 31    # include /etc/nginx/conf.d/*.conf;
 32     server   {
 33         listen       80;
 34         server_name  www.oldboy.com;
 35         location / {
 36         root   /usr/share/nginx/html/www;
 37         index  index.html index.htm;
 38         }
 39     }
 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 }

7.404 not found

[root@web01 ~]# cat /user/share/nginx/html/{www,blog}/index.html
www oldboy.com
blog oldboy.com
[root@web01 ~]# vim /etc/hosts
[root@web01 ~]# curl blog.oldboy.com
<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.403 Forbidden

原因1:没有权限
原因2:站点目录中首页文件不存在

模拟权限不足的403
[root@web01 ~]# cd /usr/share/nginx/html/www/
[root@web01 /usr/share/nginx/html/www]# ll
total 4
-rw-r--r-- 1 root root 15 Jun  5 08:39 index.html
[root@web01 /usr/share/nginx/html/www]# chmod 000 index.html 
[root@web01 /usr/share/nginx/html/www]# ll
total 4
---------- 1 root root 15 Jun  5 08:39 index.html
[root@web01 /usr/share/nginx/html/www]# 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>
[root@web01 /usr/share/nginx/html/www]# chmod 644 index.html 
[root@web01 /usr/share/nginx/html/www]# ll
total 4
-rw-r--r-- 1 root root 15 Jun  5 08:39 index.html
模拟首页文件不存在的403

首页文件不存在 默认找首页文件 403

[root@web01 /usr/share/nginx/html/www]# ll
total 0
[root@web01 /usr/share/nginx/html/www]# 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>

9.Cannot assign requested address

无法分配指定的ip地址
本地没有10.0.0.9ip

[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地址

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

解决方法2 :修改内核参数

[root@web02 conf.d]# cat  /proc/sys/net/ipv4/ip_nonlocal_bind 
0
[root@web02 conf.d]# echo 1 >/proc/sys/net/ipv4/ip_nonlocal_bind
[root@web02 conf.d]# nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web02 conf.d]# nginx 
[root@web02 conf.d]# ss -lntup |grep nginx 
tcp    LISTEN     0      128    10.0.0.10:80                    *:*                   users:(("nginx",pid=9233,fd=6),("nginx",pid=9232,fd=6),("nginx",pid=9231,fd=6),("nginx",pid=9230,fd=6),("nginx",pid=9229,fd=6))
[root@web02 conf.d]# #10.0.0.3 
[root@web02 conf.d]# #10.0.0.4 

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

11. 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

[root 12:16:28 @web01 ~]# cat /etc/nginx/nginx.conf 

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    include /etc/nginx/conf.d/*.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:29:17 @web01 conf.d]# vim 02-blog.conf 

server {
      listen    80;
      server_name       blog.oldboy.com;

      #charset koi8-r;
      access_log  /var/log/nginx/access_blog.log  main;

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

[root 12:30:38 @web01 conf.d]# cat 03-status.conf 
server {
        listen  80;
        server_name  status.oldboy.com;
        stub_status on;
        access_log off;


} 
 
[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;
    }
}

12. 401 Authorization Required

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

13. 500 Internal Server Error

原因1:
设置了权限认证auth_basic_user_file 密码文件权限不对导致的

14. invalid variable name

[root@web01 /etc/nginx/conf.d]# nginx -t 
nginx: [emerg] invalid variable name in /etc/nginx/conf.d/01-www.conf:18
nginx: configuration file /etc/nginx/nginx.conf test failed
server {
    listen       80;
    server_name  www.oldboy.com;
    root   html/www;
    location / {
       return 200  "location / \n";
    }
    location = / {
        return 200 "location = \n";
    }

    location /documents/ {
        return 200 "location /documents/ \n";
    }
    location ^~ /images/ {
        return 200 "location ^~ /images/ \n";

    }
    location ~* \.(gif|jpg|jpeg)$ {
        return 200 "location ~* \.(gif|jpg|jpeg)$ \n";
    }
    access_log off;
}

15. no route to host

无法到达主机

1.失联
2.防火墙 selinux

16. Unit is masked.

单元被屏蔽
检查nginx的systemctl配置文件
systemctl cat nginx 可以发现
原因,/usr/lib/systemd/system/nginx.serivce 文件被清空 和nginx命令被清空
解决 从 其他机器复制过来即可。

[root@lb02 /etc/nginx]# systemctl start nginx
Failed to start nginx.service: Unit is masked.

17. 编译安装nginx故障 /configure: error: SSL modules require the OpenSSL library.

configure的时候报错 ,ssl模块 需要安装openssl 库
解决yum install openssl-devel #development

/configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

18. 编译安装 配置的错误

xxxx and xxxx are same file
./configure --prefix=解压的目录
解决: --prefix指定其他目录

image.png
image.png

MySQL 故障

ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

错误: 使用wordpress用户在localhost(本地登录)权限拒绝 (密码是正确的)
解决: MySQL添加用户分为远程登录权限和本地登录权限
这里添加的用户是172.16.1.% 远程登录权限
需要登录的时候加上-h ,本地登录需要授权wordpress@localhost

MariaDB [(none)]> grant all on wordpress.*   to 'wordpress'@'172.16.1.%'  identified  by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from  mysql.user ;
+-----------+------------+
| user      | host       |
+-----------+------------+
| root      | 127.0.0.1  |
| wordpress | 172.16.1.% |
| root      | ::1        |
|           | localhost  |
| root      | localhost  |
|           | web01      |
| root      | web01      |
+-----------+------------+
7 rows in set (0.01 sec)

MariaDB [(none)]> Bye
[root@web01 ~]# mysql -uwordpress -p123456 
ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270

推荐阅读更多精彩内容