zoukankan      html  css  js  c++  java
  • http错误代码

    408:请求超时(Request time out)

    The 408 Request Timeout is an HTTP response status code indicating that the server did not receive a complete request from the client within the server’s allotted timeout period. The 408 Request Timeout error  code appears similar to the 504 Gateway Timeouterror we explored in a previous article, which indicates that that a server acting as a gateway or proxy timed out. However, the 408 Request Timeout error isn’t a message from a gateway or proxy server somewhere in the node chain, but is a direct message from the active server the client has connected to (like a the web server)
     

    原因:服务器关闭了请求链接.

            client_header_timeout:Http核心模块指令,指令指定读取客户端请求头标题的超时时间。 这里的超时是指一个请求头没有进入读取步骤,如果连接超过这个时间而客户端没有任何响应,Nginx将返回一个"Request time out" (408)错误。            client_body_timeout:Http核心模块指令,指令指定读取请求实体的超时时间。 这里的超时是指一个请求实体没有进入读取步骤,如果连接超过这个时间而客户端没有任何响应,Nginx将返回一个"Request time out" (408)错误

      如何避免:

    2、调整nginx配置增大超时时间配置

    499错误:

    google定义:

    499 / ClientClosed Request

        An Nginx HTTP server extension. This codeis introduced to log the case when the connection is closed by client whileHTTP server is processing its request, making server unable to send the HTTP header back

    维基百科定义:

    499Client Closed Request (Nginx)

    Used in Nginx logs to indicate when the connection has been closed by client while the server is still processing itsrequest, making server unable to send a status code back

    Nginx源码:

    grep一下nginx源码,定义在ngx_request_t.h :

    1
    2
    3
    4
    5
    6
    7
    /*
    * HTTP does notdefine the code for the case when a client closed
    * the connectionwhile we are processing its request so we introduce
    * own code to logsuch situation when a client has closed the connection
    * before we even tryto send the HTTP header to it
    */
    #define NGX_HTTP_CLIENT_CLOSED_REQUEST 499

    这是nginx定义的一个状态码,用于表示这样的错误:服务器返回http头之前,客户端就提前关闭了http连接

    继续grep :

    wKioL1ZK_oWDZn9NAAC_HrhuQAs422.png


    很有可能是因为服务器端处理的时间过长,客户端不耐烦

    要解决此问题,就需要在程序上面做些优化了。

     

    再grep下“NGX_HTTP_CLIENT_CLOSED_REQUEST”,发现目前这个状态值只在ngx_upstream中赋值


    upstream在以下几种情况下会返回499:

    1
    2
    3
    4
    5
    6
    7
    8
    (1)upstream 在收到读写事件处理之前时,会检查连接是否可用:
    ngx_http_upstream_check_broken_connection,
        if (c->error) { //connecttion错误
         ……
            if (!u->cacheable) { //upstream的cacheable为false,这个值跟http_cache模块的设置有关。指示内容是否缓存。
                ngx_http_upstream_finalize_request(r, u, NGX_HTTP_CLIENT_CLOSED_REQUEST);
            }
    }

    如上代码,当连接错误时会返回499。

    (2)server处理请求未结束,而client提前关闭了连接,此时也会返回499。

    (3)在一个upstream出错,执行next_upstream时也会判断连接是否可用,不可用则返回499。

    总之,这个错误的比例升高可能表明服务器upstream处理过慢,导致用户提前关闭连接。而正常情况下有一个小比例是正常的。

    继续分析:

    问题的核心就是要排查为什么服务端处理时间过长

    可能问题

    1      后台python程序处理请求时间过长

    2      mysql慢查询

    通过查看监控:

    1  cpu和内存的使用,都在正常范围

    2  后台程序访问正常

    3  MySQL没有慢查询

     解决方法:

    降低服务器处理时间。增大内存 

    1、java进行异步处理利用线程。import java.util.concurrent.Executors + import java.util.concurrent.Future + RanAble/Callable(为什么??)
     

     500:

    原因:服务器内部错误(Internal Server Error)。

    解决:消除bug

     404:

    HTTP 404 Not Found客户端错误响应代码指示服务器找不到请求的资源。导致404页面的链接通常被称为断开或死链接。 404状态代码不表示资源是暂时还是永久缺失。但是,如果资源被永久删除,应该使用410(Gone)而不是404状态

    400:

    超文本传输​​协议(HTTP)400错误请求响应状态码指示服务器由于语法无效而无法理解请求。 如:请求缺少请求参数

  • 相关阅读:
    2019ICPC上海站
    “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛(2018)
    集合问题
    后缀数组
    141. 周期(KMP)
    求和(矩阵快速幂)
    大数(KMP)
    1270: [蓝桥杯2015决赛]完美正方形
    AC自动机
    8.26作业
  • 原文地址:https://www.cnblogs.com/sy-liu/p/8534510.html
Copyright © 2011-2022 走看看