在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

posted on 2014-06-25 19:10  幸福之家128817  阅读(899)  评论(0编辑  收藏  举报