我正在运行Etherpad ,它通过nginx代理。 Etherpad使用带有Socket.io的Websockets。
我的nginxconfiguration或多或less是这一个 。 socket.io的位置块是这样的:
rewrite /CustomSubDir/socket.io/(.*) /socket.io/$1 break; proxy_pass http://localhost:CustomPort/; proxy_redirect / /CustomSubDir/; proxy_cookie_path / /CustomSubDir/; # usual proxy header 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 X-NginX-Proxy true; # websocket proxy_set_header Accept-Encoding ""; proxy_http_version 1.1; # http://nginx.org/en/docs/http/websocket.html proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; proxy_buffers 8 32k; proxy_buffer_size 64k; proxy_buffering off;
所以好消息是: 一切正在工作! 因此,我不问如何得到任何工作。
基本的一点是:虽然一切正常nginx总是显示我的错误信息。
nginx在error.log显示我这些错误:
2016/05/24 xx:yy:zz [error] 22197#0: *12059 connect() failed (111: Connection refused) while connecting to upstream, client: SOM.IPA.DDR.EES, server: somedomain.example.com, request: "GET /CustomSubDir/socket.io/?EIO=3&transport=polling&t=1464121868147-3&sid=H2GhIY24t2a40etpAACd HTTP/2.0", upstream: "http://[::1]:CustomPort/socket.io/?EIO=3&transport=polling&t=1464121868147-3&sid=H2GhIY24t2a40etpAACd", host: "somedomain.example.com" 2016/05/24 xx:yy:zz [error] 22197#0: *12070 connect() failed (111: Connection refused) while connecting to upstream, client: SOM.IPA.DDR.EES, server: somedomain.example.com, request: "POST /CustomSubDir/socket.io/?EIO=3&transport=polling&t=1464122037998-5&sid=T-pthraR669TF2cKAACe HTTP/2.0", upstream: "http://[::1]:CustomPort/socket.io/?EIO=3&transport=polling&t=1464122037998-5&sid=T-pthraR669TF2cKAACe", host: "somedomain.example.com"
所以我可以跟踪这个请求。 这是为什么:1.这显然是WebSocket的请求。 这些都是 – 特别的 – POST请求。
当加载一个Etherpad或者在一个丢失的连接之后重新连接到一个时,只有一个请求被执行,这满足了这些要求。 我可以在浏览器中清楚地看到它,并且可以实时看到它出现在nginx错误日志中。 这是我的浏览器中的请求:
200 POST https://somedomain.example.com/CustomSubDir/socket.io/?EIO=3&transport=polling&t=1464121868143-2&sid=H2GhIY24t2a40etpAACd
它包含(例如)这个有效载荷:
164:42["message",{"component":"pad","type":"CLIENT_READY","padId":"CENSORED","sessionID":"null","password":null,"token":"t.qbszmj[...]","protocolVersion":2}]
服务器回复是:
HTTP/2.0 200 OK Server: nginx Date: Tue, 24 May 2016 xx:yy:zz GMT Content-Type: text/html Content-Length: 2 access-control-allow-origin: * Set-Cookie: io=H2GhIY24t[...] X-Firefox-Spdy: h2 ok
我很确定POST请求导致这一点。 不仅因为它是唯一的POST请求与这个URL访问垫时,我也可以比较行为。 因为在同一台服务器上,我也运行Etherdraw ,它的工作原理非常相似,但它有一个重要的区别:它似乎不使用POST WebSocket请求。
你猜怎么着? error.log是空的。
那么我的问题是什么?
我可以通过@ webzwo0i解决我的问题,他让我意识到GitHub可能是IPv4 / IPv6冲突。
所以我再次查看错误日志,我特别注意到这一点:
“[…]连接()失败(111:连接被拒绝)连接到上游[…]”,上游:“http:// [:: 1] :CustomPort / socket.io / […] ]”
这是IPv6本地主机地址,但Etherpad / NodeJS似乎只连接到IPv4地址。
所以将nginxconfiguration中的所有localhost改为127.0.0.1解决了我的问题。 日志中的错误消失了。 我还注意到其他一些请求也在日志中导致了相同的错误,所以它不是特定于我所描述的请求。