Project

General

Profile

[Solved] websocket-connection over lighttpd-reverse-proxy to websocket-server

Added by Collin01 over 2 years ago

I use lighttpd on a gateway as a reverse proxy.
Access to devices in the LAN is managed with it.
This works fine for http.

Now there is the requirement that the proxy should be used to access a local service that provides a websocket. The server run on its on local nework port.

The websocket is provided by websocketpp 0.7.0.

I tried to reach the websocket via mod_proxy.

$ SERVER ["socket"] == ": 8081" {
   $ HTTP ["url"] = ~ "^ / socket" {
     proxy.server = ("" => (("host" => "127.0.0.1", "port" => "81")))
     proxy.header = ("upgrade" => "enable")
   }
}

After a successful connection, I would expect that the local websocket send data back.
This works with a direct connection from client to websocket-server.
If I use the lighttpd revverse proxy, the connection is closed after 60 seconds.
I assume no end-to-end connection was made.

I don't understand anything yet. Who can help me here?

For testing I use the "Chrome Websocket Test Client"


Replies (5)

RE: websocket-connection over lighttpd-reverse-proxy to websocket-server - Added by gstrauss over 2 years ago

Please see How to get support

Your syntax above has incorrect spaces in the line
$ SERVER ["socket"] == ": 8081" {
That is probably a mistake in cut-n-paste for this post.

I don't understand anything yet. Who can help me here?
For testing I use the "Chrome Websocket Test Client"

Have you tried a search engine for how to troubleshoot the Chrome Websocket Test Client?

lighttpd websockets demonstration using lighttpd for websocket termination can found in lighttpd mod_wstunnel doc.

RE: websocket-connection over lighttpd-reverse-proxy to websocket-server - Added by Collin01 over 2 years ago

Operating System: Yocto Linux: Linux 5.10.42 SMP PREEMPT 2021 armv7l GNU/Linux
CPU i.MX 6
Lightttpd: lighttpd/1.4.59 (ssl)
Version of lighttpd: lighttpd -v
lighttpd -tt --> OK
Clients: Any Browser (Chrome, Edge, Firefox) --> Test with F12 - integrated developer tools
What client you used (Firefox, Chrome, browser, curl, etc.)

Szenario 1: I open a website with integrated websocket connection (JavaScript), the websocket is open and running without any termination.

Szenario 2: I open over lighttpd as reverse proxy. A websocket connection is also created and connect to the webserver process, but the connection is terminated after 60seconds.

I think, it is a problem, that the connection is terminated.

Configuration of the reverse proxy for websocket:

$SERVER["socket"] == ":8081" {
  $HTTP["url"] =~ "^/websocket" {
    proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "81" ) ) )
    proxy.header = ( "upgrade" => "enable" )
  }
}

RE: websocket-connection over lighttpd-reverse-proxy to websocket-server - Added by gstrauss over 2 years ago

lighttpd mod_proxy works just fine in front of a simple websocket echo server (https://pypi.org/project/simple-websocket-server/)

lighttpd configuration options can be found on the aptly named Configuration Options page on the front page of the lighttpd wiki.
server.max-read-idle (default 60 seconds)
server.max-write-idle (default 360 seconds)
This is lighttpd working exactly as designed and documented. Please spend some more time reading the documentation.

RE: [Solved] websocket-connection over lighttpd-reverse-proxy to websocket-server - Added by Collin01 over 2 years ago

Thank you very much for your support.
In my understanding, my question was not a error issue. I requested support only. The header from this forum is 'Support'.
Your answer help me. Thanx.

RE: [Solved] websocket-connection over lighttpd-reverse-proxy to websocket-server - Added by gstrauss over 2 years ago

You wrote:

I think, it is a problem, that the connection is terminated.

and you wrote:

my question was not a error issue.

One suggests a problem, and the other says that you were not suggesting a problem.

My response clarified:

This is lighttpd working exactly as designed and documented. Please spend some more time reading the documentation.

    (1-5/5)