【问题标题】:nginx client_max_body_size is not working correctlynginx client_max_body_size 工作不正常
【发布时间】:2020-03-04 15:54:01
【问题描述】:

我正在尝试上传文件,当api直接调用时它工作正常,但是当它在代理后面时它没有,我使用nginx作为反向代理

NGINX -v nginx版本:nginx/1.15.0

同样经过 1.17 测试 操作系统:CentOS 7.0

即使我在 http 块中将 client_max_body_size 设置为 30M,ajax 请求也会在 chrome 网络监视器上被取消!

Forntend:React,使用 axios

后端:nodejs 10

我尝试将最大大小放在 http、服务器或位置中,并且没有任何响应。

我错过了什么吗?

http 设置:

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

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;

client_body_in_file_only clean;
client_body_buffer_size 32K;
client_max_body_size 30M;


keepalive_timeout  65;

#gzip  on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
}

server {
    listen 80;
    server_name my_server_name;
    return 301 https://my_server_name;
}
server {

listen 443 ssl default_server;
server_name my_server_name;
ssl_certificate     path_to_cert;
ssl_certificate_key path_to_key;
root  path_to_build;
index index.html index.htm;

client_body_in_file_only clean;
client_body_buffer_size 32K;
client_max_body_size 30M;

location /api/ {
    proxy_set_header   X-Forwarded-For $remote_addr;
    proxy_set_header   Host $http_host;
    proxy_pass http://127.0.0.1:3003/api/;
    proxy_pass_request_headers on;
    proxy_cache                off;

client_body_in_file_only clean;
client_body_buffer_size 32K;
client_max_body_size 30M;

}
location / {

            try_files $uri /index.html;
    }
}

还删除了 client_body_in_file_only 和 client_body_buffer_size 并且仍然相同

任何帮助将不胜感激

【问题讨论】:

    标签: node.js nginx centos axios formidable


    【解决方案1】:

    其实我是因为网速慢找到了答案,我只是增加了超时时间,问题就解决了!

    【讨论】:

      猜你喜欢
      • 2017-01-02
      • 2017-07-07
      • 2022-10-15
      • 2018-02-20
      • 2015-04-13
      • 1970-01-01
      • 2022-06-11
      • 2012-02-21
      • 2023-02-24
      相关资源
      最近更新 更多