【问题标题】:Suspected nginx client_max_body_size not working on 408 errors怀疑 nginx client_max_body_size 无法处理 408 错误
【发布时间】:2017-12-25 05:01:34
【问题描述】:

我有一个 Hapi.js,Node 后端配置为从我的 React 前端接受最大 20M 的文件,可以很好地在没有 NGINX 的情况下上传开发中的大文件。当我在生产中包含 NGINX 时,浏览器中出现 408 错误,但 NGINX 错误日志中没有任何内容。

由于只有小于 1MB 的文件可以成功上传,我认为问题在于 client_max_body 大小为默认 1MB。但是,无论我在哪里增加它(即:http、服务器、位置),它都没有效果。这是我的整个 NGINX 配置。

我想知道是否有其他人遇到过这种情况,或者知道为什么 408 错误没有出现在日志中?非常感谢您的帮助。

events {
        worker_connections 1024;
        # multi_accept on;
}

http {

        sendfile                          on;
        tcp_nopush                        on;
        tcp_nodelay                       on;
        keepalive_timeout                 65;
        types_hash_max_size               2048;

        client_header_timeout             3m;
        client_body_timeout               3m;
        send_timeout                      3m;
        client_header_buffer_size         1k;
        large_client_header_buffers       4 4k;

        client_max_body_size              20M;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;


        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        gzip on;
        gzip_disable "msie6";

        server {
                listen 80 default_server;
                listen [::]:80 default_server;

                client_max_body_size 20M;

                server_name _;
                root /var/www/front;
                index index.html index.htm;

                location ~* \.(?:manifest|appcache|html?|xml|json)$ {
                        add_header Access-Control-Allow-Origin *;
                        expires -1;
                        client_max_body_size 20M;
                }

                location ~* \.(?:css|js)$ {
                        add_header Access-Control-Allow-Origin *;
                        try_files $uri =404;
                        expires 1y;
                        access_log off;
                        add_header Cache-Control "public";
                        client_max_body_size 20M;
                }

                location ~ ^.+\..+$ {
                        add_header Access-Control-Allow-Origin *;
                        try_files $uri =404;
                        client_max_body_size 20M;
                }

                location / {
                        add_header Access-Control-Allow-Origin *;
                        try_files $uri $uri/ /index.html;
                        client_max_body_size 20M;
                }


                location /api {
                        proxy_set_header Access-Control-Allow-Origin *;
                        proxy_pass http://my-ip-address:3000;
                        proxy_http_version 1.1;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection 'upgrade';
                        proxy_set_header Host $host;
                        proxy_cache_bypass $http_upgrade;

                        client_max_body_size 20M;

                        client_body_buffer_size 128k;
                        client_body_temp_path /var/nginx/client_body_temp;
                        proxy_connect_timeout 70;
                        proxy_send_timeout 90;
                        proxy_read_timeout 90;
                        proxy_buffer_size 4k;
                        proxy_buffers 4 32k;
                        proxy_busy_buffers_size 64k;
                        proxy_temp_file_write_size 64k;
                        proxy_temp_path /var/nginx/proxy_temp;
                }


        }
}

【问题讨论】:

    标签: reactjs nginx hapijs


    【解决方案1】:

    当我遇到 body size 问题时,nginx 会给我一个 413 错误,我可以使用 client_max_body_size 修复它,所以这可能是其他问题。

    根据 nginx 文档,由于 client_body_timeout 或 client_header_timeout 中的设置,可能会返回 408 错误,但您的已设置为 3m,所以我也不知道这是否适用。也许尝试将这些值设置得非常高,看看是否有帮助?

    【讨论】:

      猜你喜欢
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多