Project

General

Profile

[Solved] using websocket

Added by gepito over 3 years ago

Hi,

I would like to set up lighty to be websocket capable.

What I've tried is the basic websocket application:
https://paste.lighttpd.net/48#ja8oWYIlj5IdSDLDj7FBPkUx
My lighttpd config is:
https://paste.lighttpd.net/38#aX8XDQ8CDBZgAHKYQh56gEcx

i.e. I expect lighttpd will forward the websocket request to the internal 8069 port.

I run
ncat --exec "/bin/tee log.log" -l 8069 --keep-open
I know from https://redmine.lighttpd.net/boards/2/topics/9348?r=9400#message-9400 and https://redmine.lighttpd.net/boards/2/topics/7906?r=7912#message-7912
that using netcat as backend is discouraged. Nevertheless, it should indicate if anything passed to the backend. Shouldn't?

When I request for https://paste.lighttpd.net/48#ja8oWYIlj5IdSDLDj7FBPkUx
the page got served (no wonder), but I can not see any activity on 8069 port!?

I tried to forward via both mod_proxy, mod_wstunnel modules, using {ws|tun}
neither
var wsUri = "192.168.18.102/ws";
nor
var wsUri = "vss://192.168.18.102/ws";
in https://paste.lighttpd.net/48#ja8oWYIlj5IdSDLDj7FBPkUx
is working.

Any suggestions are welcome :)

The OS is CentOS 8.2
Lightty is built from source: lighttpd/1.4.59-devel-lighttpd-1.4.58-2-g693a29fe - a light and fast webserver

Best regards
Balazs


Replies (9)

RE: using websocket - Added by gstrauss over 3 years ago

Check your config
$HTTP["url"] =~ "/ws/" { will match URLs which contain /ws/, but your test URL 192.168.18.102/ws does not have an ending slash.
Perhaps you meant $HTTP["url"] =~ "^/ws" { ? A similar mistake applies to $HTTP["url"] =~ "/tun/" { in your config.

RE: using websocket - Added by gstrauss over 3 years ago

BTW, related to one of your links above, lighttpd -1 (one-shot mode) works with netcat in lighttpd 1.4.56 and later. However, that is not relevant to your use in this topic.

RE: using websocket - Added by gepito over 3 years ago

well, one error of mine was using
- var wsUri = "wss://192.168.18.102/ws";-
the correct one should be something like
var wsUri = "ws://192.168.18.102/ligws";

My new config, and HTML are respectively:
https://paste.lighttpd.net/58#ZINSjpr08q4awaMyJLlXLHPo
https://paste.lighttpd.net/68#LCZlKJZGSgPbJtkXGsll1fF8

So I still try to redirect the websocket request to port 8069
But no activity on 8069 and in the access.log I see

192.168.18.102 192.168.18.102 - [10/Jan/2021:21:33:57 +0100] "GET /websocket.htm HTTP/1.1" 200 1458 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"
192.168.18.102 192.168.18.102 - [10/Jan/2021:21:33:57 +0100] "GET /ligws HTTP/1.1" 404 341 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"

why?

RE: using websocket - Added by gepito over 3 years ago

OK, I've just read...
I try the ending slash hint :)

RE: using websocket - Added by gepito over 3 years ago

:))

with
var wsUri = "ws://192.168.18.102/ligws/";
I see
192.168.18.102 192.168.18.102 - [10/Jan/2021:21:49:17 +0100] "GET /websocket.htm HTTP/1.1" 200 1459 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"
192.168.18.102 192.168.18.102 - [10/Jan/2021:21:49:18 +0100] "GET /ligws/ HTTP/1.1" 502 345 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"

and the request is forwarded.
Now I have only to prepare the backend.

Thanks for the great support, on this late hour :> !

RE: using websocket - Added by gepito over 3 years ago

BTW according to
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Configuration
=~ : perl style regular expression match

and according to
https://www.tutorialspoint.com/perl/perl_regular_expressions.htm
Match Regular Expression - m//
and
You can omit m from m// if the delimiters are forward slashes

so
$HTTP["url"] =~ "/ligws/"
should match ligws (without slashes) shouldn't?

But I can live together with this feature certainly :)

RE: using websocket - Added by gepito over 3 years ago

well, OK it should not.
Sorry, I'm not a perl expert.
Let's forget the previous post!

RE: [Solved] using websocket - Added by gstrauss over 3 years ago

URL paths tend to have / in them.

lighttpd use of PCRE is not Perl, but rather the PCRE library (perl-compatible regular expressions). The places in lighttpd.conf where you use regular expressions are the regular expression, not the Perl syntax to indicate start and end of a regular expression with the regular expression in between. In lighttpd, the regular expression is within a double-quoted string, not m/.../

RE: [Solved] using websocket - Added by stbuehler over 3 years ago

(Even in perl / is not fixed; you can also use m#...# or s#...#...#)

    (1-9/9)