2010-12-06 48 views
12

當我嘗試上傳文件到我的網站時,我得到Nginx「413請求實體太大」的錯誤,但是在我的nginx.conf文件中,我已經明確聲明最大尺寸是目前大約爲250MB,並且在php.ini中也更改了最大文件大小(是的,我重新啓動了這些進程)。錯誤日誌給了我這樣的:Nginx錯誤413

2010/12/06 4時15分06秒[錯誤] 20124#0: * 11975客戶打算送過大的身體:1144149個字節,客戶端: 60.228.229.238 ,服務器:www.x.com,請求: 「POST /上傳HTTP/1.1」,主機: 「x.com」,引薦: 「http://x.com/」

作爲據我所知,1144149字節不是250MB ... 有什麼我在這裏失蹤?

這裏的基礎Nginx的配置:

user nginx; 
worker_processes 8; 
worker_rlimit_nofile 100000; 

error_log /var/log/nginx/error.log; 
#error_log /var/log/nginx/error.log notice; 
#error_log /var/log/nginx/error.log info; 

pid  /var/run/nginx.pid; 


events { 
    worker_connections 1024; 
    use epoll; 
} 


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; 
    client_max_body_size 300M; 
    tcp_nopush  on; 
    tcp_nodelay  on; 
    server_tokens off; 
    gzip   on; 
    gzip_static  on; 
    gzip_comp_level 5; 
    gzip_min_length 1024; 
    keepalive_timeout 300; 
    limit_zone myzone $binary_remote_addr 10m; 

    # Load config files from the /etc/nginx/conf.d directory 
    include /etc/nginx/sites/*; 
} 

而且該網站的虛擬主機:

server { 
    listen  80; 
    server_name www.x.com x.com; 

    access_log /var/log/nginx/x.com-access.log; 

    location/{ 
     index index.html index.htm index.php; 
     root /var/www/x.com; 

     if (!-e $request_filename) { 
      rewrite ^/([a-z,0-9]+)$ /$1.php last; 
      rewrite ^/file/(.*)$ /file.php?file=$1; 
     } 

     location ~ /engine/.*\.php$ { 
      return 404; 
     } 

     location ~ ^/([a-z,0-9]+)\.php$ { 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include  fastcgi_params; 
     } 
    } 
} 
+0

您應該引用已更改的nginx配置設置 – 2010-12-06 11:19:43

+0

好的,補充。 – EJay 2010-12-06 11:27:48

回答

11

不知道你的nginx的構建的版本,哪些模塊它是用做這個艱難的建成,但請嘗試以下操作:

  1. 複製您的client_max_body_size 300M;行到您的虛擬主機配置的位置/ {}部分。我不確定是否正確覆蓋默認值(即1 MB)。

  2. 你使用的是nginx_upload_module?如果是這樣,請確保您擁有upload_max_file_size 300MB;在你的配置中也是如此。

-1

我還補充一點,你可以在* .PHP位置處理

location ~ ^/([a-z,0-9]+)\.php$ { 

作爲一個在級聯層次「較低」一個定義,這將是一個簡單的方法,看看是否問題來自你的nginx配置或模塊。

它肯定不是來自PHP,因爲413錯誤「body too large」實際上是一個NGinx錯誤。

+0

不知道爲什麼我在這個答案downvoted?謹慎解釋? – nembleton 2014-10-29 15:12:07

1

我的設置是:

的php.ini

... 
upload_max_filesize = 8M 
... 

nginx.conf

... 
client_max_body_size 8m; 
... 

nginx的顯示錯誤413,當它被上傳。

然後,我有一個想法:我不會讓nginx的顯示錯誤413,client_max_body_size設置爲大於upload_max_filesize的值,因此:

的php.ini

... 
upload_max_filesize = 8M 
... 

nginx的。conf

... 
client_max_body_size 80m; 
... 

發生了什麼事?

上傳時間小於80MB時,nginx不會顯示錯誤413,但如果文件高達8MB,PHP將顯示錯誤。

這解決了我的問題,但是如果有人上傳大於80MB的文件錯誤413發生,nginx規則。