W3cubDocs

/Varnish

Adding WebSockets support

WebSockets is a technology for creating a bidirectional stream-based channel over HTTP.

To run WebSockets through Varnish you need to pipe the request and copy the Upgrade and Connection headers as follows:

sub vcl_recv {
    if (req.http.upgrade ~ "(?i)websocket") {
        return (pipe);
    }
}

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

Copyright © 2006 Verdens Gang AS
Copyright © 2006–2020 Varnish Software AS
Licensed under the BSD-2-Clause License.
https://varnish-cache.org/docs/6.5/users-guide/vcl-example-websockets.html