![]() | |
WebSocket proxying | english русский 简体中文 עברית 日本語 türkçe news about download security advisories documentation pgp keys faq links books support donation trac wiki nginx.com |
To turn a connection between a client and server from HTTP/1.1 into WebSocket, the protocol switch mechanism available in HTTP/1.1 is used.
There is one subtlety however: since the “Upgrade” is a
hop-by-hop
header, it is not passed from a client to proxied server.
With forward proxying, clients may use the Since version 1.3.13, nginx implements special mode of operation that allows to set up a tunnel between a client and proxied server if the proxied server returned a response with the code 101 (Switching Protocols), and the client asked for a protocol switch via the “Upgrade” header in a request. As noted above, hop-by-hop headers including “Upgrade” and “Connection” are not passed from a client to proxied server, therefore in order for the proxied server to know about the client’s intention to switch a protocol to WebSocket, these headers have to be passed explicitly: A more sophisticated example in which a value of the “Connection” header field in a request to the proxied server depends on the presence of the “Upgrade” field in the client request header:
|