fatedier / frp

A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.
Apache License 2.0
80.5k stars 12.74k forks source link

[Feature Request] 我现在想使用URL路由 根据访问的路由代理到不同的服务器,比如 访问www.baidu.com:8060/aaa 代理到本机1.100的80端口,访问www.baidu.com:8060/bbb代理到本机1.110的80端口.服务器端和客户端怎么配置呢 请教 #4198

Closed WWTBNBWN closed 1 week ago

WWTBNBWN commented 2 weeks ago

Describe the feature request

我现在想使用URL路由 根据访问的路由代理到不同的服务器,比如 访问www.baidu.com:8060/aaa 代理到本机1.100的80端口,访问www.baidu.com:8060/bbb代理到本机1.110的80端口.服务器端和客户端怎么配置呢 请教

Describe alternatives you've considered

No response

Affected area

xqzr commented 1 week ago
# frps.toml
vhostHTTPPort = 8060
# frpc.toml
[[proxies]]
name = "aaa"
type = "http"
localIP = "127.0.1.100"
localPort = 80
customDomains = ["www.baidu.com"]
locations = ["/aaa"]

[[proxies]]
name = "bbb"
type = "http"
localIP = "127.0.1.110"
localPort = 80
customDomains = ["www.baidu.com"]
locations = ["/bbb"]

https://gofrp.org/zh-cn/docs/features/http-https/route/

WWTBNBWN commented 1 week ago

我看着文档配置过一次。我就是上述配置 frps bindPort = 7000

tcpmuxHTTPConnectPort = 8099

vhostHTTPPort = 8090

frpc serverAddr = "88.88.88.88" serverPort = 7000

frpc.toml

webServer.addr = "127.0.0.1" webServer.port = 7002 webServer.user = "admin" webServer.password = "admin"

[[proxies]] name = "bbb" type = "http" localPort = 80 localIP = "192.168.1.164" customDomains = ["www.aaa.aaa"] remotePort = 8090 locations = ["/bbb"]

[[proxies]] name = "aaa" type = "http" localPort = 80 localIP = "192.168.1.108" remotePort = 8090 customDomains = ["www.aaa.aaa"] locations = ["/aaa"] 访问浏览器 www.aaa.aaa:8090/aaa 页面直接提示 Access Error: 404 -- Not Found Can't locate document: /aaa frps的日志 2024/05/04 08:05:37 [I] [service.go:563] [f858b1a9b5d18616] client login info: ip [121.14.15.87:45791] version [0.53.2] hostname [] os [windows] arch [amd64] 2024/05/04 08:05:37 [I] [http.go:110] [f858b1a9b5d18616] [aaa] http proxy listen for host [www.aaa.aaa] location [/aaa] group [], routeByHTTPUser [] 2024/05/04 08:05:37 [I] [control.go:401] [f858b1a9b5d18616] new proxy [aaa] type [http] success 2024/05/04 08:05:37 [I] [http.go:110] [f858b1a9b5d18616] [bbb] http proxy listen for host [www.aaa.aaa] location [/bbb] group [], routeByHTTPUser [] 2024/05/04 08:05:37 [I] [control.go:401] [f858b1a9b5d18616] new proxy [bbb] type [http] success

xqzr commented 1 week ago
locations = ["/aaa/"]
locations = ["/bbb/"]
WWTBNBWN commented 1 week ago
locations = ["/aaa/"]
locations = ["/bbb/"]

结果一样的,浏览器也是提示Access Error: 404 -- Not Found Can't locate document: /aaa 我试了。还有什么其他的方案吗 不能使用nginx还有其他的吗 谢谢

xqzr commented 1 week ago
locations = ["/aaa/"]
locations = ["/bbb/"]

结果一样的,浏览器也是提示Access Error: 404 -- Not Found Can't locate document: /aaa 我试了。还有什么其他的方案吗 不能使用nginx还有其他的吗 谢谢

看起来是 本地服务返回的错误 你的场景 可能需要 frpc 改写请求路径(/aaa/bbb 改写为 /)再请求 本地服务,而 frpc 没有这个功能。可以让本地服务适应。

另外,可以看看使用端口 路由它们

# frpc.toml
[[proxies]]
name = "aaa"
type = "tcp"
localIP = "127.0.1.100"
localPort = 80
remotePort = 8010

[[proxies]]
name = "bbb"
type = "tcp"
localIP = "127.0.1.110"
localPort = 80
remotePort = 8011
WWTBNBWN commented 1 week ago
locations = ["/aaa/"]
locations = ["/bbb/"]

结果一样的,浏览器也是提示Access Error: 404 -- Not Found Can't locate document: /aaa 我试了。还有什么其他的方案吗 不能使用nginx还有其他的吗 谢谢

看起来是 本地服务返回的错误 你的场景 可能需要 frpc 改写请求路径(/aaa/bbb 改写为 /)再请求 本地服务,而 frpc 没有这个功能。可以让本地服务适应。

另外,可以看看使用端口 路由它们

# frpc.toml
[[proxies]]
name = "aaa"
type = "tcp"
localIP = "127.0.1.100"
localPort = 80
remotePort = 8010

[[proxies]]
name = "bbb"
type = "tcp"
localIP = "127.0.1.110"
localPort = 80
remotePort = 8011

tcp的我试了是可以的但是这样需要大量端口。如果我单独访问每台机器的ip(http://192.168.1.100)是可以的访问的。我就是想少开端口通过路由来访问。但是没找到方案。您这有什么方式么

vikii0210 commented 1 week ago

frpc+nginx hahaha