我有一个nginx代理请求的图片上传服务。 一切都很好。 有时候,服务器已经有了用户正在上传的图片。 所以,我想尽早回复并closures连接。
在读取头文件并检查服务器之后,我调用Node的response.end([data] [,encoding] [,callback]) 。
Nginx barfs并返回一个空白的响应:
[error] 3831#0: *12879 readv() failed (104: Connection reset by peer) while reading upstream
我的猜测是,nginx假设上游服务器发生了一些不好的事情,立即丢弃客户端连接而不发送上游服务器的响应。
有没有人知道如何正确回应和closures客户端的连接,当nginx是代理? 我知道这是可以做的: 请参阅:发送请求之前的响应
这里是nginx conf文件:
worker_processes 8; # the number of processors worker_rlimit_nofile 128; # each connection needs 2 file handles events { worker_connections 128; # two connections per end-user connection (proxy) multi_accept on; use kqueue; } http { sendfile on; tcp_nopush on; # attempt to send HTTP response head in one packet tcp_nodelay off; # Nagle algorithm, wait until we have the maximum amount of data the network can send at once keepalive_timeout 65s; include nginx.mime.types; default_type application/octet-stream; error_log /usr/local/var/log/nginx/error.log; log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; gzip off; } upstream upload_service { server 127.0.0.1:1337 fail_timeout=0; keepalive 64; } location /api/upload_service/ { # setup proxy to UpNode proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header Connection ""; proxy_pass http://upload_service; # The timeout is set only between two successive read operations proxy_read_timeout 500s; # timeout for reading client request body, only for a period between two successive read operations client_body_timeout 30s; # maximum allowed size of the client request body, specified in the "Content-Length" client_max_body_size 64M; }
你没有提到你的客户是什么,但是,这听起来像你会用期望的头来实现的东西。 从本质上说,客户端设置一个“期望”头,并带有“100次继续”的期望。 然后,客户端在发送请求主体之前,等待来自服务器的100次继续响应。
如果服务器不想接收主体,它可以响应最终状态,客户端不会发送主体。
此过程在RFC2616的第8.2.3节中定义