nginx代理服务器无法上传大于1 MB的文件

时间:2017-03-02 07:02:49

标签: nginx

下面是我正在使用的nginx conf(nginx是一个docker容器) - Nginx用作所有后端api服务器的代理服务器。当我尝试上传文件时,如果大小超过1 MB,我会收到错误。尝试了所有可能的解决方案,但是没有解决。任何帮助都会有用。

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

void setup() {
    Serial.begin(9600); // Initialize serial communications with the PC
    SPI.begin();            // Init SPI bus
    mfrc522.PCD_Init(); // Init MFRC522 card    
}

void loop() {
    String code = "";
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
    }

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
    }

    for (byte i = 0; i < mfrc522.uid.size; i++) {
      code += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" :"");
      code += String(mfrc522.uid.uidByte[i], HEX);
    }
    Serial.println(code);
    mfrc522.PICC_HaltA();
}

我可以上传任何小于1MB的文件,但是上传的文件较大。低于错误 -

server {
    listen 80;
    server_name abcd.dev;
    #rewrite ^/(.*)/$ /$1 permanent;
    charset utf-8;
    keepalive_timeout 300s;
    gzip on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_buffers 16 8k;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    client_body_in_file_only clean;
    client_body_buffer_size 10M;
    client_max_body_size 10M;

    sendfile on;
    send_timeout 300s;

    proxy_buffering off;
    proxy_request_buffering off;
    proxy_buffer_size 10M;
    proxy_buffers 32 4m;
    proxy_busy_buffers_size 10m;
    proxy_max_temp_file_size 1024m;
    proxy_temp_file_write_size 10m;

    proxy_connect_timeout 300s;
    proxy_read_timeout 300s;
    proxy_send_timeout 300s;


    proxy_set_header HOST $host;

    #X-Forwarded-Proto header gives the proxied server information about the schema of the original client request (whether it was an http or an https request).
    proxy_set_header X-Forwarded-Proto $scheme;

    #The X-Real-IP is set to the IP address of the client so that the proxy can correctly make decisions or log based on this information.
    proxy_set_header X-Real-IP $remote_addr;

    #The X-Forwarded-For header is a list containing the IP addresses of every server the client has been proxied through up to this point.
    #In the example above, we set this to the $proxy_add_x_forwarded_for variable.
    #This variable takes the value of the original X-Forwarded-For header retrieved from the client and adds the Nginx server's IP address to the end.
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    error_page 404 /custom_404.html;
        location = /custom_404.html {
                root /usr/share/nginx/html;
                internal;
        }

    error_page 500 502 503 504 /custom_50x.html;
        location = /custom_50x.html {
                root /usr/share/nginx/html;
                internal;
    }

    location / {
      location ~ ^/(uploads/|vendor/|images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
            proxy_pass http://ui-service;
      }
      if ($domain) {
        set $args $args&nethumUrl=$domain;
        proxy_pass http://ui-service$uri$is_args$args;
      }
      proxy_pass http://ui-service$uri$is_args$args;

    }
...........
}

3 个答案:

答案 0 :(得分:1)

upload_max_filesize上的php.ini设置是什么?还尝试在http指令(在/etc/nginx/nginx.conf中)以及location指令中添加client_max_body_size 10M;

答案 1 :(得分:1)

我有一种问题。它通过微调下一个(后面的nginx)Web服务器来解决。但是,http部分中的一些设置可以提供帮助

default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  300;
client_max_body_size 100m;
gzip  on;

答案 2 :(得分:0)

错误消息表明您的后端(Java服务器)已关闭连接。检查日志以找出问题来源。