Running a varnish redirect to a node js server with socket.io

So I’m running a website, on the front it’s a simple apache home page nothing important. But I want to run a sync client on a subdomain ( https://github.com/calzoneman/sync )

backend apache {
    .host = "127.0.0.1";
    .port = "8051";
    .connect_timeout = 1s;
}

backend node {
    .host = "127.0.0.1";
    .port = "8081";
    .connect_timeout = 1s;
}



backend bot {
    .host = "127.0.0.1";
    .port = "8080";
    .connect_timeout = 1s;
}





sub vcl_recv {
    if(req.http.host == "Base-domain.com") {
        set req.backend = apache;
    }
    if(req.http.host == "bot.base-domain.com") {
        set req.backend = bot;
    }
	
	    if(req.http.host == "sync.base-domain.com") {
        set req.backend = node;
    }
	
  if (req.http.Upgrade ~ "(?i)websocket") {
    set req.backend = node;
    return (pipe);
  }

  if (req.http.host == "sync.based-domain.moe") {  
    if (req.url ~ "^/socket.io/") {
        set req.backend = node;
        return (pipe);  
    }
    return (pass);  
  }

}

sub vcl_pipe {
  if (req.http.upgrade) {
    set bereq.http.upgrade = req.http.upgrade;
  }
}

Searching all over for information on how to run the node JS as the one with a socket is turning up no help. Due to a connection issue the websocket is on 1338 rather than 1337. Pretty new to this so not sure what to do.

Should I be changing my varnish or modification the node’s config further? Thanks in advance.


Source: apache

Leave a Reply