• 上传文件返回413错误同时出现has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header...


    背景:由于上传apk版本出现413的错误,同时报出跨域问题,但是测试环境没有出现该问题

    原因:因为生产环境请求的接口是nginx反向代理时后的域名。测试环境没有配置nginx直接是ip+端口号请求。

    解决方法:在ngixn.conf配置文件中添加 client_max_body_size属性值。

    Syntax: client_max_body_size size;

    Default:  client_max_body_size 1m;   (默认是1M)
    Context: http, server, location
    Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field.

    If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.

    Please be aware that browsers cannot correctly display this error.

    Setting size to 0 disables checking of client request body size.

    可以选择在http{ }中设置:client_max_body_size   20m;

    也可以选择在server{ }中设置:client_max_body_size   20m;

    还可以选择在location{ }中设置:client_max_body_size   20m;

    三者到区别是:http{} 中控制着所有nginx收到的请求。而报文大小限制设置在server{}中,则控制该server收到的请求报文大小,同理,如果配置在location中,则报文大小限制,只对匹配了location 路由规则的请求生效。

  • 相关阅读:
    day006 数字类型和字符串类型的内置方法
    awk技巧 nginx access.log
    测试访问速度
    ELK Deployed
    jenkins权限控制
    linux 系统优化
    nginx 刷新显示404
    虚拟机安装的ubutun全屏
    在线生成二维码
    GIT 命令集
  • 原文地址:https://www.cnblogs.com/wang-yaz/p/12664512.html
Copyright © 2020-2023  润新知