2017-03-02 135 views
2

下面是我使用的nginx conf(nginx是一個docker容器) - Nginx被用作所有後端api服務器的代理服務器。當我嘗試上傳文件時,如果尺寸大於1 MB,則會出現錯誤。嘗試了所有可能的解決方案,但無法解決。任何幫助都會有用。nginx代理服務器無法上傳大於1 MB的文件

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; 

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

我可以上傳小於1MB的文件,但上傳的文件不大。獲取以下錯誤 -

error 2017/03/02 06:52:37 [error] 38#38: *89 recv() failed (104: Connection reset by peer) while reading response header from upstream 
+0

你可以設置位置塊內的配置'client_max_body_size' PARAM&再試一次? –

+0

錯誤消息表示連接被您的後端重置。你能從你的java後端顯示日誌嗎? –

+1

請注意,儘管代理服務器默認使用http/1.0。你在下面說,上傳到你的Java應用程序直接工作正常 - 讓我們嘗試在你的測試客戶端明確使用http/1.0或使用proxy_http_version 1.1來確保你的測試是公平的。是的,從你的Java應用程序的任何日誌將是有益的,否則我們只能猜測發生了什麼 – ffeast

回答

0

什麼是您的php.ini設置upload_max_filesize?還要嘗試在您的http指令(位於/etc/nginx/nginx.conf)中以及location指令中添加client_max_body_size 10M;

+0

我不使用PHP。它是一個向Java服務器發送請求的代理服務器,我也有一個10M的限制。如果我直接上傳到我的Java服務器,它工作正常。 – Ananda

0

錯誤消息表明連接被後端(Java服務器)關閉。檢查它日誌找出問題來源。

+0

路徑是nginx-> node-proxy-> java app – Ananda

+0

@Ananda你可以顯示node-proxy和java app的日誌嗎?看起來問題的根源在於其中之一。 –

1

我有一種問題。這是通過微調下一個(後面的nginx)web服務器解決的。然而,這裏是http節的一些設置,可以幫助

default_type application/octet-stream; 
sendfile  on; 
keepalive_timeout 300; 
client_max_body_size 100m; 
gzip on; 
相關問題