How to create lighttpd proxy rule to redirect to different ports based on url parameter?

Currently, lighttpd.conf

there is a rule proxy.server

that forwards all requests routemsg.pl

to port 1530:

$HTTP["url"] =~ "/routemsg.pl" {
    proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => 1528) ) )
}

      

How do I change the rule to allow the requestor to pass a port parameter in the url, and that parameter will then be used as the port to proxy the request?

For example: the request http://www.myip.com/routemsg.pl?p=1531

will be sent 127.0.0.1

to port 1531.

+2


source to share


1 answer


You can try using $HTTP["querystring"]

and grabbing the port with a condition like this:

$HTTP["url"] =~ "/routemsg.pl" {
    $HTTP["querystring"] =~ "p=([0-9]+)" {
        proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "%1") ) )
    }
}

      



I unfortunately do not have a setting on which I can confirm that it works right now, I'm afraid. :(

+2


source







All Articles