# Unexpected response code:400 while using nginx\_tcp\_proxy\_module for WebSocket

**URL:** <https://www.ruby-forum.com/t/unexpected-response-code-400-while-using-nginx-tcp-proxy-module-for-websocket/222159>\
**Category:** NGINX\
**Created:** [August 15, 2012, 4:30pm UTC](https://www.ruby-forum.com/t/unexpected-response-code-400-while-using-nginx-tcp-proxy-module-for-websocket/222159 "2012-08-15T16:30:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 15, 2012, 4:30pm UTC](https://www.ruby-forum.com/t/unexpected-response-code-400-while-using-nginx-tcp-proxy-module-for-websocket/222159/1 "2012-08-15T16:30:24Z")

</div>

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](http://comet.example.com)  
Origin: [http://comet.example.com](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](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:

> **[Unexpected response code:400 while using nginx\_tcp\_proxy\_module for WebSocket](https://forum.nginx.org/read.php?2,229724,229724#msg-229724)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [August 15, 2012, 5:54pm UTC](https://www.ruby-forum.com/t/unexpected-response-code-400-while-using-nginx-tcp-proxy-module-for-websocket/222159/2 "2012-08-15T17:54:34Z")

</div>

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: removed\_email\_address@domain.invalid

Thanks.

2012/8/15 n1xman [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
