【问题标题】:NGINX client_max_body_size issueNGINX client_max_body_size 问题
【发布时间】:2018-02-20 03:27:23
【问题描述】:

我有一个关于 nginx client_max_body_size 的问题。我遇到了类似

的问题

2017/09/11 13:21:02 [错误] 6126#6126: *150091 客户端打算发送太大的正文:1219514 字节,客户端:10.160.90.909,服务器:example.com,请求:“POST / api/sensors HTTP/1.1”,主机:“example.com”。

收到 413 nginx 错误。我只想知道我应该在哪里添加(插入)client_max_body_size 以及您建议的推荐 mb 是什么..?请在下面找到我的 nginx.conf 文件

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    index   index.html index.htm;
upstream nodejs {
    server localhost:3000;
}
    server {
        listen       80;
        server_name  example.com;

location / {
if ($http_x_forwarded_proto != 'https') {
            return 301 https://$server_name$request_uri;
        }
        try_files $uri $uri/ @nodejs;
    }

    location @nodejs {
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_pass http://nodejs;
        proxy_set_header Host $host ;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
location ~ (/images|/img|/javascript|/js|/css|/stylesheets|/flash|/media|/static|robots.txt|humans.txt|favicon.ico){
root /var/www/dev/public;
}
        # redirect server error pages to the static page /40x.html
        #
        error_page 404 /404.html;
            location = /40x.html {
        }
        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
}
}

【问题讨论】:

标签: nginx configuration reverse-proxy


【解决方案1】:

您需要将其插入您的 @nodejs 块中。因为上传正在那里发送。您当前的失败指示大小为 1.16 MB。

因此,请检查您希望/期望一次接收的最大数据量。因此,如果您希望它最大为 5MB,请将其设置为 5.5MB 或更高以提供一些缓冲

【讨论】:

    猜你喜欢
    • 2011-06-24
    • 2020-12-31
    • 2015-04-13
    • 2012-02-21
    • 2017-01-02
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多