我的机器上有两个网络服务器在运行。一个监听8080端口,另一个监听8081端口。
$ curl http://localhost:8080
I am the API
$ curl http://localhost:8081
Flat file
I am the flat flile 我希望设置一个中继,根据HTTP请求的请求路径将通信转发给其中一个或另一个。这是我的/etc/relayd.conf
$ cat /etc/relayd.conf
api_host="127.0.0.1"
api_port="8080"
table {$api_host}
flat_host="127.0.0.1"
flat_ports="8081"
table {$flat_host}
log state changes
log connection
http protocol "chatty" {
pass request path "/api/*" forward to
pass request path "/*" forward to
}
relay "forum.cwal.net" {
listen on 0.0.0.0 port 80
protocol "chatty"
forward to port $api_port
forward to port $flat_ports
}但是,似乎所有的请求都会发送到端口8081上的服务器。
$ curl http://localhost
Flat file
I am the flat flile
$ curl http://localhost/api
404 Not Found
<!--
body { background-color: white; color: black; font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }
hr { border: 0; border-bottom: 1px dashed; }
-->
404 Not Found
OpenBSD httpd在最后一个请求中,我希望看到"I the the API“请求,但我没有。
发布于 2020-07-14 11:34:13
IRC上有人给我解释过了。因为中继规则是在“最后胜利”的基础上运行的,所以我需要我最具体的比赛才能出现在最后。下面这些对我来说很有用。
table { 127.0.0.1 }
table { 127.0.0.1 }
http protocol "PROTOX" {
match request path "/*" forward to
match request path "/api/*" forward to
}
relay "RELAYX" {
listen on 0.0.0.0 port 80
protocol "PROTOX"
forward to port 8080
forward to port 8081
}https://serverfault.com/questions/1025117
复制相似问题