1. 程式人生 > >Nginx出現413 Request Entity Too Large錯誤

Nginx出現413 Request Entity Too Large錯誤

Nginx Nginx 413錯誤

一. 問題出現

使用phpMyAdmin管理mysql數據,使用圖形界面導入sql語句時報錯,報錯內容如下:

技術分享圖片

二. 問題原因

出現了413錯誤,413錯誤是因為用戶請求body的數據大於設置的值。用戶請求的body的值可用Content-Length看到

技術分享圖片

可以看到請求的body大小大於6M,通過查看Nginx官網可知默認request body為1M,而設置request body的參數為client_max_body_size

三. 解決問題的方法

修改client_max_body_size,此參數的用法為:

Syntax:     client_max_body_size size;
Default:  client_max_body_size 1m;
Context:    http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size. 

nginx配置文件修改:

    location /phpMyAdmin {
        root /opt;
        client_max_body_size 10m;
        index index.php;
        location ~ \.php$ {
            fastcgi_index index.php;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

四. 參考資料

Nginx client_max_body_size的使用方法:http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

Nginx出現413 Request Entity Too Large錯誤