nginx ajax 错误500,聊聊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连接,常见于后台接口处理时间比较长,而前端请求又自带有超时时间。

复现

请求实例

$(document).ready(function(){

$("button").click(function(){

$.ajax({

url : '/demo/test',

timeout : 10000,

type : 'get',

dataType : 'json',

success : function(data){

alert('success');

}

});

});

});

ajax带超时时间请求

后台接口

@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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值