上传大文件时Nginx返回501

时间:2017-02-28 11:54:26

标签: nginx

当我将10M文件上传到服务器时,Nginx会返回501错误。但是上传较小的文件确定。

<html>
<head><title>501 Not Implemented</title></head>
<body bgcolor="white">
<center><h1>501 Not Implemented</h1></center>
<hr><center>nginx/1.8.1</center>
</body>
</html>

的access.log

  

[01 / Mar / 2017:10:13:29 +0800]&#34; POST / boss / cgi / importemoji HTTP / 1.1&#34; 501   582

Nginx配置文件是

http {
    include       mime.types;
    #default_type  application/octet-stream;
    default_type  text/plain;
    access_log  logs/access.log  main;
    #access_log off;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  30;
    keepalive_requests 100;

    gzip  on;

    #gzip_disable msie6;

    proxy_max_temp_file_size 0;
    proxy_buffer_size 20M;
    proxy_buffers 4 20M;

    #mail_spam add url, host will be mod
    #server_name_in_redirect off;

    proxy_connect_timeout 60;
    proxy_read_timeout 120;
    proxy_send_timeout 120;

    client_header_buffer_size 20M;
    client_max_body_size 80M;
    client_body_buffer_size 60M;
    client_body_temp_path /usr/local/qspace/nginx/client_body_temp;
    client_header_timeout 1m;
    client_body_timeout 1m;

    server_names_hash_max_size 1024;
    server_names_hash_bucket_size 1024;

    proxy_set_header Host  $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Real-Port $remote_port;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header PROXY_FORWARDED_FOR "disabled";

    server {
        listen       80;
        listen 443  ssl;
        keepalive_timeout 70;
        ...
    }

}

error.log中

2017/03/01 10:41:10 [debug] 6167#6167: *132144 __mydebug. menshen cleanup r: 00000000011DD720
2017/03/01 10:41:11 [debug] 6171#6171: *132871 __mydebug_menshen. ngx_http_dummy_payload_handler wait_for_body: yes
2017/03/01 10:41:11 [debug] 6171#6171: *132871 status: unkown. uri: /boss/cgi/importemoji args:  r: 00000000011DD720 r->main: 00000000011DD720 r->count: 1
2017/03/01 10:41:11 [debug] 6171#6171: *132871 __mydebug_menshen. ngx_http_menshen_handler is called r: 00000000011DD720 nginx_version: 1008001
2017/03/01 10:41:11 [debug] 6171#6171: *132871 status: send. uri: /boss/cgi/importemoji. args:  r: 00000000011DD720 r->main: 00000000011DD720 r->count: 1
2017/03/01 10:41:11 [debug] 6171#6171: *132871 __mydebug_menshen. len: 3078 header: 
POST /boss/cgi/importemoji HTTP/1.1
Proxy-Connection:keep-alive
Content-Length:9465320
Pragma:no-cache
Cache-Control:no-cache
Accept:application/json, text/javascript, */*; q=0.01

我尝试将使用CURL的10M文件直接上传到服务器,这是好的。所以问题可能来自Nginx。

如何修复错误?

1 个答案:

答案 0 :(得分:1)

我已经解决了这个问题。通常,在Nginx上遇到上传大文件错误时存在这些点

  • 文件大小限制。修改client_max_body_size
  • 保持活动连接超时。修改keepalive_timeout
  • 反向代理超时。修改proxy_connect_timeout

最后你必须确保 Nginx是Native 。在这种情况下,我的公司编译一个名为 Menshen 的模块作为Nginx的防火墙。它只允许传递小于8M的文件上传请求。