[GH-ISSUE #2393] http 路由模式, 可以对路径重写吗? 类似 Nginx 的路径重写. #1900

Closed
opened 2026-05-05 13:13:36 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @Nisus-Liu on GitHub (May 13, 2021).
Original GitHub issue: https://github.com/fatedier/frp/issues/2393

# frpc.ini
[web01]
type = http
local_port = 80
custom_domains = web.example.com
locations = /

[web02]
type = http
local_port = 81
custom_domains = web.example.com
locations = /news,/about

http://web.example.com/news 访问到 web02 服务, 但是 web02 接受到请求路径带了 /news 前缀.
有这个前缀, web02 服务可能会导致错误的资源访问.
可以做到配置将 /news 前缀去掉吗?
类似 Nginx 的路径重写.

Originally created by @Nisus-Liu on GitHub (May 13, 2021). Original GitHub issue: https://github.com/fatedier/frp/issues/2393 ``` # frpc.ini [web01] type = http local_port = 80 custom_domains = web.example.com locations = / [web02] type = http local_port = 81 custom_domains = web.example.com locations = /news,/about ``` `http://web.example.com/news` 访问到 web02 服务, 但是 web02 接受到请求路径带了 `/news` 前缀. 有这个前缀, web02 服务可能会导致错误的资源访问. 可以做到配置将 `/news` 前缀去掉吗? 类似 Nginx 的路径重写.
gitea-mirror 2026-05-05 13:13:36 -06:00
  • closed this issue
  • added the
    proposal
    label
Author
Owner

@fatedier commented on GitHub (May 14, 2021):

暂时没有这样的计划,这一部分会比较复杂,frp 通常只做简单的路由,可以在你自己的服务前挡一个 nginx 来完成,否则就相当于在 frp 中逐渐实现 nginx 中的功能,有点本末倒置。

不过也许之后会尝试在 frpc 这一层提供一个可选的类似 nginx 这样的 HTTP server 的插件,提供一些丰富的基于 HTTP 的扩展能力。这样可以把这部分独立在主项目之外,可以单独维护。

<!-- gh-comment-id:840953964 --> @fatedier commented on GitHub (May 14, 2021): 暂时没有这样的计划,这一部分会比较复杂,frp 通常只做简单的路由,可以在你自己的服务前挡一个 nginx 来完成,否则就相当于在 frp 中逐渐实现 nginx 中的功能,有点本末倒置。 不过也许之后会尝试在 frpc 这一层提供一个可选的类似 nginx 这样的 HTTP server 的插件,提供一些丰富的基于 HTTP 的扩展能力。这样可以把这部分独立在主项目之外,可以单独维护。
Author
Owner

@Nisus-Liu commented on GitHub (May 14, 2021):

嗯, 有道理. 我现在就是用 nginx 来处理的. 3Q~

<!-- gh-comment-id:840960258 --> @Nisus-Liu commented on GitHub (May 14, 2021): 嗯, 有道理. 我现在就是用 nginx 来处理的. 3Q~
Author
Owner

@Greybeetle commented on GitHub (Aug 20, 2021):

你好,请问你是怎么实现的呢,是要在服务端配置nginx还是客户端上配置?

<!-- gh-comment-id:902543834 --> @Greybeetle commented on GitHub (Aug 20, 2021): 你好,请问你是怎么实现的呢,是要在服务端配置nginx还是客户端上配置?
Author
Owner

@Greybeetle commented on GitHub (Aug 20, 2021):

我的frps.ini配置如下

[common] 
server_addr = ***.***.***.***
server_port = 7000

[web1]
type = tcp
local_port = 5001
remote_port = 5001
custom_domains = web.example.com

[web2]
type = tcp
local_port = 7001
remote_port = 7001
custom_domains = web.example.com

然后我在服务器上配置了nginx,代码如下:

server {
    listen       4545;
    server_name web.example.com;
   
    # location / {
    #     proxy_pass  https://web.example.com:5001;
    # }

    location /dsm {
        proxy_pass  https://web.example.com:5001;
    }

    location /file {
        proxy_pass  https://web.example.com:7001;
    }
}

通过web.example.com:4545/dsm 或者 web.example.com:4545/file 均没有办法访问对应的服务。但是在不配置路由的情况下,直接使用

    location / {
        proxy_pass  https://web.example.com:5001;
    }

则可以通过web.example.com:4545访问第一个服务,请能帮忙看看我的思路有什么问题吗

<!-- gh-comment-id:902574936 --> @Greybeetle commented on GitHub (Aug 20, 2021): 我的frps.ini配置如下 ``` [common] server_addr = ***.***.***.*** server_port = 7000 [web1] type = tcp local_port = 5001 remote_port = 5001 custom_domains = web.example.com [web2] type = tcp local_port = 7001 remote_port = 7001 custom_domains = web.example.com ``` 然后我在服务器上配置了nginx,代码如下: ``` server { listen 4545; server_name web.example.com; # location / { # proxy_pass https://web.example.com:5001; # } location /dsm { proxy_pass https://web.example.com:5001; } location /file { proxy_pass https://web.example.com:7001; } } ``` 通过web.example.com:4545/dsm 或者 web.example.com:4545/file 均没有办法访问对应的服务。但是在不配置路由的情况下,直接使用 ``` location / { proxy_pass https://web.example.com:5001; } ``` 则可以通过web.example.com:4545访问第一个服务,请能帮忙看看我的思路有什么问题吗
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#1900
No description provided.