Nginx proxy with cometd websocket

393 views
Skip to first unread message

Neha Kaushik

unread,
Jan 30, 2014, 12:33:52 AM1/30/14
to cometd...@googlegroups.com
Hi,

Cometd 2.7
Nginx 1.4.4
Jetty 8

I am trying to use Nginx proxy with cometd websocket but it is not working. I am able to do the websocket handshake and send my first request to the server but it doesn't return any response back. If i make my connection-type as long-polling it is working fine. Can you let me know what is wrong with my nginx config file. 

Here's the config file

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    
    server {
        listen       80;
        server_name  test.abc.com;

       location / {
          proxy_pass http://110.90.22.202:8080;
          proxy_redirect off;
          #root /var/;

          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "Upgrade";
          proxy_set_header X-Nginx-Proxy true;
       }

       error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }


}

Simone Bordet

unread,
Jan 30, 2014, 4:52:16 AM1/30/14
to cometd-users
Hi,

On Thu, Jan 30, 2014 at 6:33 AM, Neha Kaushik <nehakau...@gmail.com> wrote:
> Hi,
>
> Cometd 2.7
> Nginx 1.4.4
> Jetty 8
>
> I am trying to use Nginx proxy with cometd websocket but it is not working.
> I am able to do the websocket handshake and send my first request to the
> server but it doesn't return any response back. If i make my connection-type
> as long-polling it is working fine. Can you let me know what is wrong with
> my nginx config file.

I'm sorry I am not an nginx expert, so I would have to do the Googling
that you probably have done already.

Anyone ?

--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.

steven winner

unread,
Jan 30, 2014, 11:51:07 AM1/30/14
to cometd...@googlegroups.com
My only input on this matter is that while we had understood that it was possible, we proxy through nginx with long polling, only because it is a backup for us.  We have our cometd servers on a separate sub domain, and even though we have the CrossOriginFilter setup, there were a few users that would still have issues connecting, so if a user isn't connected within a few seconds, we proxy them through our nginx webserver that our site is run off of, so it is on the exact same domain, to our cometd servers, but disable websockets and just go with long polling.  Not saying it can't be done, but since it is a fallback for us, long polling isn't a terrible option for us.  For our nginx config, we just do this:

location /cometd/ {
    proxy_connect_timeout 120s;
    proxy_read_timeout 120s;
    proxy_buffering off;
}

If you figure out a reliable way to proxy websockets through nginx though, I would definitely be interested in the conf for that.

hirantha

unread,
Feb 8, 2014, 5:43:46 AM2/8/14
to cometd...@googlegroups.com
Hi
I do not see any problem on your configurations. However, for some networks websocket dose not work due to some proxies and firewall devices are not supporting Upgrade header; thus we have switched to WebSocket Secure. We are running Nginx for CometD and it is for WebSocket Secure. Here is how I configured on my systems.

        location /CometD {
        proxy_pass     http://<ip_port>/CometD;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
        # WebSocket support (nginx 1.4)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        }

We enabled cross-domain on Nginx as we streaming from different URL - https://hostname/CometD/cometd.

If this is not working you better try Nginx on debug mode and see any glitches. Let us know if it started working!

Hope this is help.

Regards
Hirantha
 
Reply all
Reply to author
Forward
0 new messages