Welcome! Log In Create A New Profile

Advanced

Proxying websocket (to e.g. tomcat)

Nikolai Zhubr
February 21, 2013 09:16AM
Hello all!

I've installed the latest version 1.3.13 (supposedly supporing
websocket) and was trying to push websocket connections through nginx to
tomcat while leaving all other (static) content to nginx. To do this,
I've added the following "location" for tomcat:

location /examples/websocket {
proxy_pass http://127.0.0.1:8080/examples/websocket;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}

I know that tomcat itself accepts some test websocket connection just
fine. Also, getting static pages from tomcat through nginx works well
too. However, proxying websocket doesn't seem to work.

So I've stopped tomcat and used netcat to see what gets through. Here it
goes:

Direct request (firefox -> tomcat):

GET /examples/websocket/echoStream HTTP/1.1
Host: 192.168.0.91:8080
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101
Firefox/17.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive, Upgrade
Sec-WebSocket-Version: 13
Origin: http://192.168.0.91:8080
Sec-WebSocket-Key: ZffbHEsoryDw1gcX51lt8g==
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

Request passed though nginx (firefox -> nginx -> tomcat):

GET /examples/websocket/echoStream HTTP/1.0
Host: 192.168.0.91
X-Real-IP: 192.168.0.98
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101
Firefox/17.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://192.168.0.91
Sec-WebSocket-Key: 9YkdANPMSHDxb8axUbeKwQ==
Pragma: no-cache
Cache-Control: no-cache

One can clearly see that there is a problem. At least, "HTTP/1.1" is
lost, "Connection: keep-alive, Upgrade" is lost, and "Upgrade:
websocket" is lost. Generally, it does not look like websocket is
supported at all (Essentially, apache does this same damage to websocket
connections).

Honestly I'm not much familiar with nginx, just had to dismiss apache
because apparently they refused to even consider support for websocket.
So before trying to dig deep into sources I thoght I should ask here. Is
it possible to get websocket through nginx really? Maybe I need to
configure something additionally?

Thank you.
Nikolai


_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Proxying websocket (to e.g. tomcat)

Nikolai Zhubr February 21, 2013 09:16AM

Re: Proxying websocket (to e.g. tomcat)

Valentin V. Bartenev February 21, 2013 09:32AM

Re: Proxying websocket (to e.g. tomcat)

Nikolai Zhubr February 21, 2013 10:38AM

Re: Proxying websocket (to e.g. tomcat)

Valentin V. Bartenev February 21, 2013 11:06AM

Re: Proxying websocket (to e.g. tomcat)

Nikolai Zhubr February 21, 2013 04:54PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 241
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready