当我尝试将file upload到基于node.js的Web应用程序时,出现以下错误:
2014/05/20 04:30:20 [error] 31070#0: *5 upstream prematurely closed connection while reading response header from upstream, client: ... [clipped]
我在这里使用一个前端代理:
upstream app_mywebsite { server 127.0.0.1:3000; } server { listen 0.0.0.0:80; server_name {{ MY IP}} mywebsite; access_log /var/log/nginx/mywebsite.log; # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://app_mywebsite; proxy_redirect off; # web socket support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }
这是我的nginx.conf文件:
user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 2048; multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 20; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; # default_type application/octet-stream; default_type text/html; charset UTF-8; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_min_length 256; gzip_comp_level 5; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
任何想法如何更好地debugging呢? 我发现的东西没有真正起作用(例如,从我的proxy_pass删除尾部的斜线
可能要检查您的节点应用程序,看看它的报告任何错误? 在过去使用nginx phpfile upload,我会得到偶尔的502由于我的文件的大小,所以我增加了它在主nginx.conf使用下面的'#Body Size client_max_body_size 900m;' 希望有所帮助
你的错误消息对我来说听起来像你的应用程序可能接受整个请求,然后死亡之前,它的响应,如果是这样,那么这是你的应用程序,你需要debugging,而不是nginx。 检查假设 – 直接validation。
对stream量进行窥探(例如使用tcpdump,ngrep和/或wireshark)来检查nginx是否成功连接到您的应用程序并将整个请求传递给它。 此检查的结果将确认您需要debugging的连接的哪一端。
可能值得testing失败是否完全取决于请求的大小。 尝试一个非常小的文件。
那么调整下面的nginx指令呢?