zoukankan      html  css  js  c++  java
  • nginx报错整理

    一、

    1、线上有个域名出现一个访问报错:

     413 Payload Too Large

    这里贴一下关于这个报错的解释:

    The 413 (Payload Too Large) status code indicates that the server is
       refusing to process a request because the request payload is larger
       than the server is willing or able to process.  The server MAY close
       the connection to prevent the client from continuing the request.

       If the condition is temporary, the server SHOULD generate a
       Retry-After header field to indicate that it is temporary and after
       what time the client MAY try again.

    于是条件反射就去改nginx的配置,在相应的server段或location段添加client_max_body_size 100m;然后reload  nginx,发现问题并没有解决。还是报错。

    有google了一番,找到关于413 Payload Too Large的解释,发现应该是后端server的问题,就开始去排查后端的服务:

    ,发现:

    Error:request entity too large

    https://github.com/expressjs/body-parser#limit

    应该是baody-parser,的问题:

    bodyParser.json([options])

    limit

    Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to '100kb'

    默认 json  limit的大小100k,我们的json已经130k了,很明显就找到问题所在了。

    接下来就是修改:

       app.use( bodyParser.json({limit: '50mb'}) );
    app.use(bodyParser.urlencoded({
      limit: '50mb',
      extended: true,
      parameterLimit:50000
    }));

    2、如果报错为413  request  entity  too large
    就应该是nginx的问题了,就需要改nginx的配置,在相应的server段或location段添加client_max_body_size 100m;然后reload  nginx

    二、

    1、记一次nginx的resolver的坑,修改了dns的地址后,执行了nginx -s reload发现并没有生效。配置如下:

    resolver 10.2.3.4;

    upstream grpcservers {
    server saturn-core.service.hq:50051;
    }

    server {
    listen 9000 http2;
    # server_name localhost;
    access_log /var/log/nginx/grpc.log main;
    error_log /var/log/nginx/grpc_error.log;
    location / {
    grpc_pass grpc://grpcservers;
    }
    }

    nginx  reload不会使dns重新解析,而是使用dns缓存,只有等到dns的TTL到期后,才会重新解析。简单粗暴的解决方案直接重启nginx,而不要使用reload。

    其他解决方案也不尽完美,还有比较看好的使用模块ngx_upstream_jdomain,在http配置域中配置DNS服务器,在upstream中按照这个模块的格式配置,支持设置每隔多少秒进行一次解析。interval可指定解析间隔,如果解析失败则使用缓存中的上一次解析结果的IP地址访问。

    http {

        resolver   10.2.3.4 ;

        upstream  grpcserver {

            jdomain  saturn-conre.service.hq:9000 interval=10; #指定域名和端口,每隔10秒进行一次解析

        }

        server {

            listen       9000 http2;

            client_body_buffer_size 10m;

            server_name  localhost;

            location / {

                    grpc_pass      grpc://grpcserver;

            }

    }

    缺点:DNS服务器只能在http配域中全局配置,并且现有的nginx编译的时候默认并没有将这个模块编译进去,使用这个功能需要重新编译。



  • 相关阅读:
    【css】所有的a标签设置为新窗口打开【原创】
    TP 3.1版本不支持 CONTROLLER_NAME
    关于TP 特殊页面伪静态规则的编写 研究实现
    larave PHP框架
    [转]git和github
    [转]mysql语句大全
    camera.swf?  提示  图片上传中请稍候,没任何报错
    mysql大小写敏感(默认为1,不敏感)
    数据cube的schema与sql的对应的关系
    MDX的实例讲解(排名前15的小例子)
  • 原文地址:https://www.cnblogs.com/cuishuai/p/8302591.html
Copyright © 2011-2022 走看看