聊聊nginx报错499问题

本文主要来聊一下nginx的access log当中出现的499问题。

问题描述

499 CLIENT CLOSED REQUEST

A non-standard status code introduced by nginx for the case when a client closes the connection while nginx is processing the request.

原因

服务器返回http头之前,客户端就提前关闭了http连接,常见于后台接口处理时间比较长,而前端请求又自带有超时时间。

复现

请求实例

<!DOCTYPE html>
<html>
<head>
<script src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.ajax({
    url : '/demo/test',
    timeout : 10000,
    type : 'get',
    dataType : 'json',
    success : function(data){
        alert('success');
    }
   });
  });
});
</script>
</head>
<body>

<button>ajax带超时时间请求</button>

</body>
</html>

后台接口

    @GetMapping("/test")
    public String test(HttpServletResponse response) throws InterruptedException {
        Thread.sleep(100*1000);
        return "hello";
    }

nginx

        location /demo/ {
            access_log  /usr/local/var/log/nginx/host.access.log  main;
            proxy_pass http://localhost:8080/demo/ ;
        }

关于log format如下

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

log实例

127.0.0.1 - - [04/Nov/2017:01:11:29 +0800] "GET /demo/test HTTP/1.1" 499 0 "http://localhost:8888/demo.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" "-"
127.0.0.1 - - [04/Nov/2017:01:11:42 +0800] "GET /demo/test HTTP/1.1" 499 0 "http://localhost:8888/demo.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" "-"
127.0.0.1 - - [04/Nov/2017:01:11:58 +0800] "GET /demo/test HTTP/1.1" 499 0 "http://localhost:8888/demo.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" "-"

doc

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,224评论 19 139
  • Page 1:nginx 服务器安装及配置文件详解 CentOS 6.2 x86_64 安装 nginx 1.1 ...
    xiaojianxu阅读 12,724评论 1 41
  • 美兰在走的时候,没想到走上的是一条不归路。 不远的黄包车上迎面来了两个人,其中一人样貌非常年轻,英俊的脸上是冷峻的...
    张企鹅阅读 1,603评论 0 0
  • 人生而孤独,却也抱持遇见知己的奢望。孤独有千万种表达,但再没什么比一个不被理解的灵魂更甚。因此,在这了无边际,繁华...
    清凉世界雨阅读 2,405评论 2 25
  • 你说想让我写点什么,我开玩笑说了句那我写你吧! 其实直到现在我也不知道我为什么要写你,大概是我们许久不见了,也许我...
    吃汤圆的丸子阅读 3,926评论 0 0

友情链接更多精彩内容