Nginx 配置大文件上傳

nginx問題

遇到的問題:nginx

  • Nginx: 413 – Request Entity Too Large Error and Solution
  • TIMEOUT

解決方法

解決方法:在nginx的配置文件下(一般爲xxx.conf),加上如下配置:shell

client_max_body_size     50m;  # 限制請求體的大小,若超過所設定的大小,返回413錯誤,默認1m
client_header_timeout    1m;  # 讀取請求頭的超時時間,若超過所設定的大小,返回408錯誤
client_body_timeout      1m; # 讀取請求實體的超時時間,若超過所設定的大小,返回413錯誤
proxy_connect_timeout     60s; # http請求沒法當即被容器(tomcat, netty等)處理,被放在nginx的待處理池中等待被處理。此參數爲等待的最長時間,默認爲60秒,官方推薦最長不要超過75秒
proxy_read_timeout      1m;  # http請求被容器(tomcat, netty等)處理後,nginx會等待處理結果,也就是容器返回的response。此參數即爲服務器響應時間,默認60秒
proxy_send_timeout      1m; # http請求被服務器處理完後,把數據傳返回給Nginx的用時,默認60秒
server {
    listen       80;
    server_name  localhost;
    
    client_max_body_size     10m;
    client_header_timeout    5m;
    client_body_timeout      5m;
    proxy_connect_timeout     6000s;
    proxy_read_timeout      5m;
    proxy_send_timeout      5m;

    location  / {
        # ...
    }
}

重啓nginx

設置完成後,須要使用 reload 或者reload重啓nginxtomcat

相關文章
相關標籤/搜索