Project

General

Profile

Use of regex backreferences in mod_proxy

Added by flyn over 2 years ago

Is it possible to use regex backtraces when configuring mod_proxy? I have been unable to find an example of this.

I am interested in proxying to a port that is present in the HTTP GET path. The requirement for this follows from my attempts at serving X2Go's web client using lighttpd. The relevant part of X2Go makes requests for wss://HOST/x2gows/PORT, which lighttpd needs to proxy to an application listening on port PORT.

The corresponding nginx configuration is at https://code.x2go.org/x2gohtmlclient?p=x2gohtmlclient.git;a=blob;f=conf/nginx/snippets/x2gohtmlclient-wswrapper.conf;h=7a038661a81800bf2bf937b81483c90f6e7a51c2;hb=HEAD.

Perhaps there is a way to satisfy this with some combination of redirect/rewrite and proxy. I have not been able to come up with such a scheme.

$ cat /etc/fedora-release
Fedora release 34 (Thirty Four)
$ lighttpd -v
lighttpd/1.4.61 (ssl) - a light and fast webserver

Replies (3)

RE: Use of regex backreferences in mod_proxy - Added by gstrauss over 2 years ago

lighttpd config conditions can match on $HTTP["url"] or $HTTP["query"] or ...
If you can match a fixed port, then you can configure a reverse proxy backend for that port.

You might also look at lighttpd mod_wstunnel, which includes an example for noVNC.

https://wiki.x2go.org/doku.php/wiki:advanced:x2goserver-in-detail
https://wiki.x2go.org/doku.php/doc:installation:x2goserver
I have not looked closely at x2go, but from a very quick read of the above, my guess is that an intermediate CGI script (or reverse proxy to another server) might be written to contact a privileged backend service which creates the session and opens firewall ports for the session (and closes those ports when the session closes). I am not sure that lighttpd is the best intermediary for the x2go service beyond initial auth and contacting a privileged backend service.

RE: Use of regex backreferences in mod_proxy - Added by flyn over 2 years ago

The trouble is that the range of possible ports is very large, and with enough sessions the ports will vary wildly. So I cannot configure a small set of static proxy entries and select them by matching the port in the URL. Thus I am searching for something like the following, but for the proxy module (from https://redmine.lighttpd.net/projects/1/wiki/docs_modrewrite):

$HTTP["host"] =~ "^.*\.([^.]+\.com)$" {
  url.rewrite-once = ( "^/(.*)" => "/%0/$1" )
}

RE: Use of regex backreferences in mod_proxy - Added by gstrauss over 2 years ago

In the original post, you wrote:

Is it possible to use regex backtraces when configuring mod_proxy?

No.

Please read my responses more carefully. I already wrote:

I am not sure that lighttpd is the best intermediary for the x2go service beyond initial auth and contacting a privileged backend service.

    (1-3/3)