Unexpected response code:400 while using nginx_tcp_proxy_module for WebSocket

Hello,

We are trying to use nginx_tcp_proxy_module for WebSocket with the
back-end
CometD/Jetty. Direct CometD exposed to public is working fine and it
goes
with WebSocket but through nginx the transport switch to long-poll after
throwing above error. Following is the request-response headers I see
while
trying to establish the WebSocket connection.

GET /CometServer/cometd HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: comet.example.com
Origin: http://comet.example.com
Sec-WebSocket-Key: yL46RAYQU5/wH73WE6y0Xw==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame
Cookie: JSESSIONID=5v8ee7guk9y61x235jgu2t3ng;
__utma=260652952.1760465236.1333589697.1333589697.1342161899.2;
__utmz=260652952.1342161899.2.2.utmcsr=;
BAYEUX_BROWSER=7e3f11lg7gmow6t4mh5welcj5oxr

HTTP/1.0 400 Bad Request
Date: Wed, 15 Aug 2012 13:12:50 GMT
Access-Control-Allow-Origin: http://comet.example.com
Access-Control-Allow-Credentials: true
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1413
Server: Jetty(7.6.3.v20120416)
X-Cache: MISS from proxy
Connection: keep-alive

I suspect this is due to CometD not seeing “Upgrade: websocket” header
thus
it considered as failed websocket request and return 400 “Unexpected
response code”

I fully understand that nginx is not natively support WebSocket as yet
but
we would like to try at least ngx_tcp_proxy module as it has a
WebSocoket
module. Following is my config.

tcp {
upstream websockets {
server 172.17.241.191:8484;
check interval=3000 rise=2 fall=5 timeout=1000;

    }

            server {
            listen  172.17.241.191:9000;
            server_name comet.example.com;
            tcp_nodelay on;
            websocket_pass websockets;

            access_log  /var/log/nginx/tcp_access.log;

    }

}

nginx -V
nginx version: nginx/1.2.1
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
TLS SNI support disabled
configure arguments: --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx
–conf-path=/etc/nginx/nginx.conf
–error-log-path=/var/log/nginx/error.log
–http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid
–lock-path=/var/run/nginx.lock
–http-client-body-temp-path=/var/cache/nginx/client_temp
–http-proxy-temp-path=/var/cache/nginx/proxy_temp
–http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
–http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
–http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx
–group=nginx
–with-http_ssl_module --with-http_realip_module
–with-http_addition_module
–with-http_sub_module --with-http_dav_module --with-http_flv_module
–with-http_mp4_module --with-http_gzip_static_module
–with-http_random_index_module --with-http_secure_link_module
–with-http_stub_status_module --with-mail_ssl_module --with-file-aio
–with-debug --with-cc-opt=’-O2 -g -m32 -march=i386 -mtune=generic
-fasynchronous-unwind-tables’ --without-http_uwsgi_module
–without-http_scgi_module --without-mail_pop3_module
–without-mail_imap_module --without-mail_smtp_module
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/yaoweibin-nginx_tcp_proxy_module-a40c99a
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/simpl-ngx_devel_kit-24202b4
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/agentzh-echo-nginx-module-080c0a1
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/agentzh-set-misc-nginx-module-87d0ab2
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/mikewest-nginx-static-etags-25bfaf9
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/nginx-sticky-module-1.0
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/agentzh-memc-nginx-module-8befc56
–add-module=/usr/local/hirantha/rpmbuild/BUILD/nginx-1.2.1/contrib/agentzh-srcache-nginx-module-8df221e

uname -rop
2.6.18-194.26.1.el5PAE i686 GNU/Linux

I would appreciate some help from you guys.

Thanks in advance.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,229724,229724#msg-229724

Hi,

Can you open an websocket for me to connect from internet? And tell me
the test method?

You can email me to my private email: [email protected]

Thanks.

2012/8/15 n1xman [email protected]:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs