首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于OpenBSD请求路径的web服务器转发

基于OpenBSD请求路径的web服务器转发
EN

Server Fault用户
提问于 2020-07-14 00:37:27
回答 1查看 891关注 0票数 3

我的机器上有两个网络服务器在运行。一个监听8080端口,另一个监听8081端口。

代码语言:javascript
复制
$ curl http://localhost:8080
I am the API 
$ curl http://localhost:8081
  Flat file
I am the flat flile  

我希望设置一个中继,根据HTTP请求的请求路径将通信转发给其中一个或另一个。这是我的/etc/relayd.conf

代码语言:javascript
复制
$ 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上的服务器。

代码语言:javascript
复制
$ 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“请求,但我没有。

EN

回答 1

Server Fault用户

发布于 2020-07-14 11:34:13

IRC上有人给我解释过了。因为中继规则是在“最后胜利”的基础上运行的,所以我需要我最具体的比赛才能出现在最后。下面这些对我来说很有用。

代码语言:javascript
复制
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
}
票数 3
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1025117

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档