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