> For the complete documentation index, see [llms.txt](https://websoft9.gitbook.io/lamp-image-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://websoft9.gitbook.io/lamp-image-guide/shi-zhan-fang-an/gu-zhang-chu-li.md).

# 故障处理

下面列出常见的故障以及应对方案

**HTTP 502 故障**

> 502 Bad Gateway

常见在LNMP上或者使用Nginx/Apache做反向代理;

故障定位:

```
LNMP:PHP-FPM 服务崩溃/服务关闭 
Nginx反向/Apache反向代理 被代理的端口关闭或被代理的程序镜像关闭
```

处理方法:

1. LNMP 重启PHP-FPM 运行命令 `systemctl restart php-fpm`
2. 重启被代理的程序

**HTTP 403 故障**

> 403 Forbidden

**故障定位:**

```

访问网站或路径没有权限
```

处理方法:

1. 检查网站目录用户和用户组是否正确目录权限,文件权限是否正确.网站目录用户和组一般为 `apache`/`nginx`/`www` 文件权限一般为`640` 文件夹权限为`750`; 运行命令 `chown apache:apache -R /data/wwwroot` 将`/data/wwwroot`目录下所有的文件和文件夹设置用户和组为`apache` ; 运行命令 `find /data/wwwroot -type d -exec chmod 750 {} \;` 和`find /data/wwwroot -not -type d -exec chmod 640 {} \;`设置`/data/wwwroot` 目录下文件夹权限`750` 文件权限`640`
2. 检查站点的配置文件,是否做了访问控制

* `apache` 检查站点配置文件中是否存在 `Require all denied` `Require host` `Require ip` `Require not ip` 等配置,`Require all granted` 设置允许所有访问请求
* `Nginx` 检查站点配置文件中是否存在 `deny all` `deny xxx.xxx.xxx.xxx`(`xxx.xxx.xxx.xxx`为IP地址),如果需要访问请删掉这些参数

1. 检查服务器上Apache是否安装有`mod_evasive` 模块,卸载`yum remove -y mod_evasive`

**HTTP 404 故障**

> 404 Not Found

**故障定位:**

```

访问网站的路径或文件不存在;Nginx伪静态设置有误
```

处理方法:

1. 检查网站的路径或文件名是否正确,输入正确的路径
2. 检查伪静态规则,正确设置伪静态规则

**HTTP 500 故障**

> 500 HTTP-Internal Server Error

**故障定位:**

```

服务器内部错误,常见与数据库连接不上,数据库连接文件参数或语法错误,错误的伪静态规则
```

处理方法:

1. 检查数据库服务器是否正常 运行命令 `netstat -anopt | grep 3306` 检查`MySQL`是否运行,没有运行的话 `systemctl start mysqld` 启动MySQL
2. 检查数据库连接文件,数据库用户名/密码/数据库名称/host地址是否有误
3. 检查伪静态规则,或关闭伪静态

**网站/服务器访问速度慢,卡**

**故障定位:**

1. 服务器配置过低/服务器宽带低
2. DDOS攻击故障检测:查看监控网卡流量，网络延迟/丢包，数据包个数/s    [检查参考](https://linux.cn/article-3160-1.html)

   ```
   DDOS攻击故障，一般是进来的流量比较大，出去的流量小。网络数据包接收包个数比较大，发送数据包比较小，网络延迟高，并且有丢包现象。
   ```
3. CC攻击故障故障检测: 查看监控网卡流量，Nginx 连接状态，CPU 负载

   ```
    CC攻击故障，一般是出去的流量比较大，进来的流量小。Nginx连接数猛增。
   ```

   看所有80端口的连接数`netstat -nat|grep -i "80"|wc -l`

&#x20;      对连接的IP按连接数量进行排序

`netstat -ntu | awk '{print $5}' | cut -d： -f1 | sort | uniq -c | sort -n`

查看TCP连接状态

`netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn`

`netstat -n | awk '/^tcp/ {++S［$NF］};END {for（a in S） print a， S［a］}'`

`netstat -n | awk '/^tcp/ {++state［$NF］}; END {for（key in state） print key，"\t"，state［key］}'`

`netstat -n | awk '/^tcp/ {++arr［$NF］};END {for（k in arr） print k，"\t"，arr［k］}'`

`netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn`

`netstat -ant | awk '{print $NF}' | grep -v '［a-z］' | sort | uniq -c`

查看80端口连接数最多的20个IP

`netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F： '{print $1}'|sort|uniq -c|sort -nr|head -n20`

`netstat -ant |awk '/：80/{split（$5，ip，"："）;++A［ip［1］］}END{for（i in A） print A，i}' |sort -rn|head -n20`

查找较多time\_wait连接

`netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20`

查找较多的SYN连接

`netstat -an | grep SYN | awk '{print $5}' | awk -F： '{print $1}' | sort | uniq -c | sort -nr | more`

​
