Nginx 文件上传暂停/中途停止(仅上传 258kb 并停止) - 408 请求超时

Amr*_*rit 6 nginx bitnami

我已经安装了 bitnami nginx 堆栈(nginx、php-fpm、mysql)来运行多个 drupal 7 和 node.js 站点,但目前只安装了一个 D7 站点。

\n\n

文件上传在本地主机中完美运行。但是,当我使用 bitnami nginx 堆栈将其上传到 Linode vps 时,它就开始显示上传问题。

\n\n

对于较小的文件(~60kb)上传效果很好。但对于较大的文件,上传会停止。少数情况:\n563KB 文件 - 上传在 46% 时停止\n3.5MB 文件 - 在 ~7% 时停止

\n\n

POST 的访问日志如下所示(给出 408):

\n\n
x.x.x.x - - [07/Sep/2014:20:15:24 +0530] "POST /node/add/profile HTTP/1.1" 408 0 "http://mysite[dot]com/node/add/profile" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36"\n
Run Code Online (Sandbox Code Playgroud)\n\n

在 nginx.conf 文件中尝试了我能做的一切,但没有任何帮助。

\n\n
 user  daemon daemon;\n worker_processes  1;\n\n error_log  logs/error.log;\n #error_log  logs/error.log  notice;\n #error_log  logs/error.log  info;\n\n #pid        logs/nginx.pid;\n\n\n events {\nworker_connections  1024;\n} \n\n\nhttp {\ninclude       mime.types;\ndefault_type  application/octet-stream;\n\n#log_format  main  \'$remote_addr - $remote_user [$time_local] "$request" \'\n#                  \'$status $body_bytes_sent "$http_referer" \'\n#                  \'"$http_user_agent" "$http_x_forwarded_for"\';\n\n#access_log  logs/access-mysite.com.log  main;\n\nsendfile        on;\n#tcp_nopush     on;\n\n#keepalive_timeout  0;\nkeepalive_timeout  65;\n\n#gzip  on;\n\nfastcgi_buffers 8 16k;\nfastcgi_buffer_size 32k;\n\nserver {\n        server_name mysite.com;\n        root /var/www/mysite; ## <-- Your only path reference.\n\n        # Enable compression, this will help if you have for instance advagg\xe2\x80\x8e module\n        # by serving Gzip versions of the files.\n        gzip_static on;\n\n    client_body_in_file_only clean;\n    client_body_buffer_size 32K;\n\n    client_max_body_size 300M;\n\n    sendfile on;\n    send_timeout 5m;\n    client_header_timeout 5m;\n    client_body_timeout 10;\n        fastcgi_max_temp_file_size 2048m;\n\n        location = /favicon.ico {\n                log_not_found off;\n                access_log off;\n        }\n\n        location = /robots.txt {\n                allow all;\n                log_not_found off;\n                access_log off;\n        }\n\n        # This matters if you use drush prior to 5.x\n        # After 5.x backups are stored outside the Drupal install.\n        #location = /backup {\n        #        deny all;\n        #}\n\n        # Very rarely should these ever be accessed outside of your lan\n        location ~* \\.(txt|log)$ {\n                allow 192.168.0.0/16;\n                deny all;\n        }\n\n        location ~ \\..*/.*\\.php$ {\n                return 403;\n        }\n\n        # No no for private\n        location ~ ^/sites/.*/private/ {\n                return 403;\n        }\n\n        # Block access to "hidden" files and directories whose names begin with a\n        # period. This includes directories used by version control systems such\n        # as Subversion or Git to store control files.\n        location ~ (^|/)\\. {\n                return 403;\n        }\n\n        location / {\n                # This is cool because no php is touched for static content\n                try_files $uri @rewrite;\n        }\n\n        location @rewrite {\n                # You have 2 options here\n                # For D7 and above:\n                # Clean URLs are handled in drupal_environment_initialize().\n                rewrite ^ /index.php;\n                # For Drupal 6 and bwlow:\n                # Some modules enforce no slash (/) at the end of the URL\n                # Else this rewrite block wouldn\'t be needed (GlobalRedirect)\n                #rewrite ^/(.*)$ /index.php?q=$1;\n        }\n\n        location ~ \\.php$ {\n                fastcgi_split_path_info ^(.+\\.php)(/.+)$;\n                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini\n                include fastcgi_params;\n                fastcgi_param SCRIPT_FILENAME $request_filename;\n                fastcgi_intercept_errors on;\n                fastcgi_pass 127.0.0.1:7777;\n        }\n\n        # Fighting with Styles? This little gem is amazing.\n        # This is for D6\n        #location ~ ^/sites/.*/files/imagecache/ {\n        # This is for D7 and D8\n        location ~ ^/sites/.*/files/styles/ {\n                try_files $uri @rewrite;\n        }\n\n        location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {\n                expires max;\n                log_not_found off;\n        }\n}\n\n\n# another virtual host using mix of IP-, name-, and port-based configuration\n#\n#server {\n#    listen       8000;\n#    listen       somename:8080;\n#    server_name  somename  alias  another.alias;\n\n#    location / {\n#        root   html;\n#        index  index.html index.htm;\n#    }\n#}\n\n\n# HTTPS server\n#\n#server {\n#    listen       443 ssl;\n#    server_name  localhost;\n\n#    ssl_certificate      cert.pem;\n#    ssl_certificate_key  cert.key;\n\n#    ssl_session_cache    shared:SSL:1m;\n#    ssl_session_timeout  5m;\n\n#    ssl_ciphers  HIGH:!aNULL:!MD5;\n#    ssl_prefer_server_ciphers  on;\n\n#    location / {\n#        root   html;\n#        index  index.html index.htm;\n#    }\n#}\n\n# client_max_body_size 300M;\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

更新:没有使用 Drupal 进行测试,只是一个简单的 PHP 脚本 - 同样的问题。绝对与 nginx/php-fpm 有关!

\n\n

更新 2:关闭 php-fpm 并仅使用带有上传字段的 html 页面进行测试。同样的问题 - 肯定是 nginx 或 bitnami!

\n

小智 1

您的 client_max_body_size 超出了服务器定义。服务器定义中的结果是什么?

另外,@PratapSingh 提出了另一个好问题 - php.ini 中的 max_upload_filesize 限制是多少?

尝试此解释以获得更多帮助。