如何创建 lighttpd 代理规则以根据 URL 参数在不同端口上重定向?

发布于 2024-08-07 02:03:00 字数 416 浏览 1 评论 0原文

我目前在 lighttpd.conf 中有一个 proxy.server 规则,它将 routemsg.pl 的所有请求转发到端口 1530:

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

如何更改规则允许请求者在 URL 中传递端口参数,然后将该参数用作代理请求的端口?

例如:http://www.myip.com/routemsg.pl?p=1531 的请求将发送至端口 1531 上的 127.0.0.1

I currently have a proxy.server rule in lighttpd.conf that forwards all requests of routemsg.pl to port 1530:

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

How can I change the rule to allow the requester to pass a port param in the URL and that param be then used as the port to proxy the request to?

For example: A request of: http://www.myip.com/routemsg.pl?p=1531 would go to 127.0.0.1 on port 1531.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2024-08-14 02:03:00

您可以尝试使用 $HTTP["querystring"] 并使用如下条件捕获端口:

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

遗憾的是,我没有可以确认它现在有效的设置,我害怕的。 :(

You could try using $HTTP["querystring"] and capture the port with a conditional like this:

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

I sadly don't have a setup on which I can confirm that it works right now, I'm afraid. :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文