499 client has closed connection:nginx自定义的状态码。服务器处理请求过慢,客户端主动断开连接。
模拟499报错,nginx配置文件如下。
http {
...
...
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
利用 sleep
停滞10秒(老板,服务器好慢啊,该加钱升级配置了!!!)。
[root@centos ~]# cat /usr/share/nginx/html/2.php
<?php
sleep(10);
?>
[root@centos ~]#
curl
有个选项可以配置请求的超时时间,这样请求1秒后就会主动断开连接。
root@okokok:~# curl -m 1 -vo /dev/null http://192.168.3.204/2.php
* Trying 192.168.3.204:80...
* TCP_NODELAY set
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 192.168.3.204 (192.168.3.204) port 80 (#0)
> GET /2.php HTTP/1.1
> Host: 192.168.3.204
> User-Agent: curl/7.68.0
> Accept: */*
>
* Operation timed out after 1000 milliseconds with 0 bytes received
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
* Closing connection 0
curl: (28) Operation timed out after 1000 milliseconds with 0 bytes received
root@okokok:~#
192.168.3.243 - - [22/Jun/2022:18:11:47 +0800] "GET /2.php HTTP/1.1" 499 0 "-" "curl/7.68.0" "-"
没看到499状态码甚至没有任何响应头部,但查看nginx访问日志有记录499状态码。

查看抓包内容,也没看到499,先是客户端主动断开连接,随后80也断开与9000端口的连接。
总结:499通常是客户端觉得服务器处理得太慢,已经不耐烦了,不想再等就主动断开连接。
太慢了?这是暗示?哦懂了,该优化或升级服务器了,快告诉老板得加钱了!!!
网友评论