標籤:style blog http tar ext com
在php中通過flash上傳檔案到伺服器端時報413錯誤,原來一直以為是php.ini配置的問題,但是檢查了php.ini的配置以後,發現不是php.ini的問題,最後是通過Http Analyzer監控然後發現問題的,在此真的感謝很Http Analyzer。
然後在百度中輸入關鍵字“413 Request Entity Too Large”,發現有一個搜尋結果是與Nginx有關的,正好我們伺服器的環境也是Nginx,按照此文章中的說明對Nginx的配置做了修改,執行/etc/init.d/nginx reload,然後重新進行上傳,不報413錯誤了,鬱悶的問題終於解決了。
以下我是修改配置的情況,就是在location上面添加了一行client_max_body_size 10m;
music1:/data/opt/nginx/conf/vhosts# more ge.mp3cn.net
server
{
listen 80;
server_name ge.mp3cn.net;
index index.php;
root /data/www/music/;
access_log off;
client_max_body_size 10m;
location ~* ^.+\.(htm|html|js|css|gif|png|jpg|xml)$
{
expires 6h;
valid_referers none blocked *.mp3cn.net mp3cn.net *.1616.net 1616.net *.1616dh.com 1616dh.com jj.com;
if ($invalid_referer) {
return 403;
}
}
location ~ .*\.php?$
{
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
php.ini中的有關選項也需要作相應的調整
;Maximum size of POST data that PHP will accept.
post_max_size = 10M
; Maximum allowed size for uploaded files.
upload_max_filesize = 10M
max_execution_time = 1800 ; Maximum execution time of each script, in seconds
max_input_time = 1800 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)
max_execution_time(max_execution_time "30" PHP_INI_ALL)可以用set_time_limit來進行設定,如用set_time_limit(0)表示不逾時。
memory_limit也可以在php程式中進行設定(memory_limit "128M" PHP_INI_ALL)
max_input_time不能在php程式中進行設定(max_input_time "-1" PHP_INI_PERDIR)
php.ini修改完成以後重啟php-fpm,/etc/init.d/php-fpm restart