0

I'm using Nginx 1.3.7 and Play! Framework 2.1 and I need to proxy my HTTP-, HTTPS- and WebSocket-connections to the Play! server through nginx.

I rely on the websocket proxy feature of the nginx trunk and I did set the "upgrade" and "connection" headers to correctly forward the headers for the websocket connections (http://nginx.org/en/docs/http/websocket.html):

 map $http_upgrade $connection_upgrade {
   default Upgrade;
   ''      close;
 }

 location / {
   proxy_pass  http://my-backend;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection $connection_upgrade;
 }

I made sure that Play! get's the correct headers during the websocket initialization. The request.headers object in Play! looks exactly the same with our without nginx.

Map(
  Cache-Control -> Buffer(no-cache),
  Connection -> Buffer(Upgrade),
  Host -> Buffer(my-backend),
  Origin -> Buffer(https://my-host:8443),
  Pragma -> Buffer(no-cache),
  Sec-WebSocket-Extensions -> Buffer(x-webkit-deflate-frame),
  Sec-WebSocket-Key -> Buffer(nk5JVO4I5QRMQnSxAJaRCg==),
  Sec-WebSocket-Version -> Buffer(13),
  Upgrade -> Buffer(websocket)
)

Here is the problem: In case the request comes from nginx the response from Play! is empty and doesn't contain any headers, just the protocol-version: "HTTP/1.1 0 ". Correctly the response from Play! would look like that:

HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Sec-WebSocket-Accept: YHVb1xdsVqaObgQxqksBQPhdkvc=
Upgrade: websocket
4

1 回答 1

1

是的,解决方案当然是使用正确版本的 nginx。1.3.7 无法转发“Connection: Upgrade”标志,因为该功能仅在 nginx 1.3.13 中引入。

我建议使用最新的 dev/trunk 版本。

于 2013-04-08T07:21:49.103 回答