NginX redirect and Vert.x WebSocket disconnect problem

745 views
Skip to first unread message

GuillaumeLakano

unread,
Jul 16, 2013, 3:55:45 AM7/16/13
to ve...@googlegroups.com
Hello,

After many time on NodeJS, I'd just discovered Vert.x 2 days ago.


I just wrote a small websocket test. When I precise the exact port in the client (ex: "ws://myweb.site:8080") this works perfectly.

But when I use NginX redirection from ":80/server" to " :8080/server" the connection works but the socket disconnect after 1 minute.
( The reason of this redirect is to bypass firewall problem, to permit the client to only use the standard 80 port. )

I precise the same example under NodeJS doesn't have this disconnect problem.


Here is the NginX configuration :
    location /server {
        proxy_set_header X
-Real-IP $remote_addr;
        proxy_set_header X
-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header
Host $http_host;
        proxy_set_header X
-NginX-Proxy true;

        proxy_pass http
://localhost:8080;
        proxy_redirect off
;

        proxy_http_version
1.1;
        proxy_set_header
Upgrade $http_upgrade;
        proxy_set_header
Connection "upgrade";
   
}




Here is the client script :

<script>
var socket = new WebSocket("ws://myweb.site:8080");         // Works perfectly
// var socket = new WebSocket("ws://myweb.site/server");    // Works but disconnect after 1 minute


socket
.onmessage = function(event) {
    alert
("Received data from websocket: ");
}

socket
.onopen = function(event) {
    alert
("Web Socket opened");
    socket
.send("Hello World");
};

socket
.onclose = function(event) {
    alert
("Web Socket closed");
};
</script>


Here is the Vert.x verticle :


var vertx       = require('vertx');
var console     = require('vertx/console');

var server = vertx.createHttpServer();
server
.websocketHandler(serverConnection);
server
.listen(8080, '0.0.0.0');

function serverConnection(client)
{
    console
.log('New connection: ' + client.path());
    client
.write(new vertx.Buffer('Welcome!'));
}



Any help would be appreciated :)

Regards,

qsys

unread,
Jul 22, 2013, 12:01:53 PM7/22/13
to ve...@googlegroups.com
Maybe a bit late, but probably proxy timeout? As far as I know, the websockets are affected by the proxy timeout.
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout
In order to keep the connection alive, you might ping once in a while (like once overy 59 seconds).

Kurt

Op dinsdag 16 juli 2013 09:55:45 UTC+2 schreef GuillaumeLakano het volgende:

Tim Fox

unread,
Jul 22, 2013, 12:29:34 PM7/22/13
to ve...@googlegroups.com
Quite possibly. Vert.x doesn't close websockets after 1 minute so it's
likely to be something else, perhaps nginx or a firewall.

GuillaumeLakano

unread,
Jul 23, 2013, 2:50:30 AM7/23/13
to ve...@googlegroups.com
Yep, this was Nginx proxy timeout.

Thanks !


Reply all
Reply to author
Forward
0 new messages