[GH-ISSUE #2641] 现在能否实现1个顶级域名下面的泛域名全部协议,进行转发? #2104

Closed
opened 2026-05-05 13:21:14 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @haifding on GitHub (Oct 30, 2021).
Original GitHub issue: https://github.com/fatedier/frp/issues/2641

Describe the feature request

现在能否实现1个顶级域名下面的泛域名全部协议,进行转发?

情况说明:
1台内网服务器IP: 192.168.0.50
1台外网服务器IP:55.55.55.55. 域名: ccc.com

我想把所有访问 *.ccc.com 这个域名(包括所有子域名)的请求全部转发到 192.168.0.50 端口都是全部对应一样的(80对80端口,443对443端口)

要怎么弄,配置文件要怎么处理。主要是我这个子域名是会不停的增加的。

Describe alternatives you've considered

No response

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @haifding on GitHub (Oct 30, 2021). Original GitHub issue: https://github.com/fatedier/frp/issues/2641 ### Describe the feature request 现在能否实现1个顶级域名下面的泛域名全部协议,进行转发? 情况说明: 1台内网服务器IP: 192.168.0.50 1台外网服务器IP:55.55.55.55. 域名: ccc.com 我想把所有访问 *.ccc.com 这个域名(包括所有子域名)的请求全部转发到 192.168.0.50 端口都是全部对应一样的(80对80端口,443对443端口) 要怎么弄,配置文件要怎么处理。主要是我这个子域名是会不停的增加的。 ### Describe alternatives you've considered _No response_ ### Affected area - [X] Docs - [ ] Installation - [ ] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
gitea-mirror 2026-05-05 13:21:14 -06:00
Author
Owner

@blizard863 commented on GitHub (Oct 30, 2021):

可以,详细阅读一下文档。

<!-- gh-comment-id:955198901 --> @blizard863 commented on GitHub (Oct 30, 2021): 可以,详细阅读一下文档。
Author
Owner

@yusanshi commented on GitHub (Nov 1, 2021):

如果要强调全部端口/协议的话,你的这个需求是做不到的;如果只是要求 80/443 端口的话是没问题的。

比如现在顶级域名 ccc.com 和某个子域名 subdomain.ccc.com 都指向 55.55.55.55,如果我没有理解错的话,你是希望 subdomain.ccc.com 的所有端口都同端口转发到内网 192.168.0.50,但是直接访问 ccc.com 和 55.55.55.55 时能继续保持指向外网服务器。如果需求是这样的话,很多协议在工作时,服务端是没有办法知道客户端要访问的 hostname 是什么(比如 SSH 服务,你 ssh user@subdomain.ccc.com -p 22ssh user@55.55.55.55 -p 22 是等价的,没法一个到达外网服务器一个到达内网服务器)。

如果只要求 HTTP/HTTPS 的话,HTTP 通过 Host Header、HTTPS 通过 Server Name Indication 来告诉服务端要访问的 hostname,这样服务端能区分请求是指向 55.55.55.55 还是 ccc.com 还是 subdomain.ccc.com,所以是可以实现的。比如下面结合 Nginx 的例子:
首先用外网服务器 8080/8443 端口来映射到内网服务器的 80/443 端口:

[range:tcp_port]
type = tcp
local_ip = 127.0.0.1
local_port = 80,443
remote_port = 8080,8443

然后外网服务器添加 Nginx 配置(以 443 为例):

server {
    listen 443 ssl;
    server_name subdomain.ccc.com; # 如果要支持所有子域名的话,换成 *.ccc.com
    ssl_certificate ...

    location / {
        proxy_pass https://127.0.0.1:8443;
        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
<!-- gh-comment-id:955864899 --> @yusanshi commented on GitHub (Nov 1, 2021): 如果要强调全部端口/协议的话,你的这个需求是做不到的;如果只是要求 80/443 端口的话是没问题的。 比如现在顶级域名 ccc.com 和某个子域名 subdomain.ccc.com 都指向 55.55.55.55,如果我没有理解错的话,你是希望 subdomain.ccc.com 的所有端口都同端口转发到内网 192.168.0.50,但是直接访问 ccc.com 和 55.55.55.55 时能继续保持指向外网服务器。如果需求是这样的话,很多协议在工作时,服务端是没有办法知道客户端要访问的 hostname 是什么(比如 SSH 服务,你 `ssh user@subdomain.ccc.com -p 22` 和 `ssh user@55.55.55.55 -p 22` 是等价的,没法一个到达外网服务器一个到达内网服务器)。 如果只要求 HTTP/HTTPS 的话,HTTP 通过 Host Header、HTTPS 通过 [Server Name Indication](https://en.wikipedia.org/wiki/Server_Name_Indication) 来告诉服务端要访问的 hostname,这样服务端能区分请求是指向 55.55.55.55 还是 ccc.com 还是 subdomain.ccc.com,所以是可以实现的。比如下面结合 Nginx 的例子: 首先用外网服务器 8080/8443 端口来映射到内网服务器的 80/443 端口: ``` [range:tcp_port] type = tcp local_ip = 127.0.0.1 local_port = 80,443 remote_port = 8080,8443 ``` 然后外网服务器添加 Nginx 配置(以 443 为例): ``` server { listen 443 ssl; server_name subdomain.ccc.com; # 如果要支持所有子域名的话,换成 *.ccc.com ssl_certificate ... location / { proxy_pass https://127.0.0.1:8443; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ```
Author
Owner

@haifding commented on GitHub (Nov 4, 2021):

[range:tcp_port]
type = tcp
local_ip = 127.0.0.1
local_port = 80,443
remote_port = 8080,8443

然后外网服务器添加 Nginx 配置(以 443 为例):

server {
    listen 443 ssl;
    server_name subdomain.ccc.com; # 如果要支持所有子域名的话,换成 *.ccc.com
    ssl_certificate ...

    location / {
        proxy_pass https://127.0.0.1:8443;
        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

我大概理解了,但是配置还是不会,运行不起来。达不到效果。

确实只需要 HTTP/HTTPS 转发就好。目的就是把内网服务器里面的网站全部给映射到外网上。

内网服务器(做web服务器) 192.168.0.50
外网服务器(就是做个转发) 55.55.55.55 域名 *.ccc.com 已经指向了该外网服务器,该域名的SSL也已经部署好了

我的内外网服务器都安装了宝塔,2台frp都正常启动了。
需求是外网访问子域名 https://a1.ccc.com 可以访问到内网服务器上的网站(内网服务器上也同样设置1个这样的域名a1.ccc.com的网站)。
至于主域名可以不用,IP也可以不用。

外网服务器的frps配置
[common]
bind_addr = 0.0.0.0
bind_port = 7000
bind_udp_port = 7001

外网的 Nginx 配置 配置了反向代理按上面的教程

内网服务器的frpc配置
[common]
server_addr = 55.55.55.55
server_port = 7000

[range:tcp_port]
type = tcp
local_ip = 127.0.0.1
local_port = 80,443
remote_port = 8080,8443

<!-- gh-comment-id:960911343 --> @haifding commented on GitHub (Nov 4, 2021): > ``` > [range:tcp_port] > type = tcp > local_ip = 127.0.0.1 > local_port = 80,443 > remote_port = 8080,8443 > ``` > > 然后外网服务器添加 Nginx 配置(以 443 为例): > > ``` > server { > listen 443 ssl; > server_name subdomain.ccc.com; # 如果要支持所有子域名的话,换成 *.ccc.com > ssl_certificate ... > > location / { > proxy_pass https://127.0.0.1:8443; > proxy_set_header Host $host; > proxy_set_header X-Real-IP $remote_addr; > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > } > } > ``` ----------------------------------------------------------------------------------- 我大概理解了,但是配置还是不会,运行不起来。达不到效果。 确实只需要 HTTP/HTTPS 转发就好。目的就是把内网服务器里面的网站全部给映射到外网上。 内网服务器(做web服务器) 192.168.0.50 外网服务器(就是做个转发) 55.55.55.55 域名 *.ccc.com 已经指向了该外网服务器,该域名的SSL也已经部署好了 我的内外网服务器都安装了宝塔,2台frp都正常启动了。 需求是外网访问子域名 https://a1.ccc.com 可以访问到内网服务器上的网站(内网服务器上也同样设置1个这样的域名a1.ccc.com的网站)。 至于主域名可以不用,IP也可以不用。 外网服务器的frps配置 [common] bind_addr = 0.0.0.0 bind_port = 7000 bind_udp_port = 7001 外网的 Nginx 配置 配置了反向代理按上面的教程 内网服务器的frpc配置 [common] server_addr = 55.55.55.55 server_port = 7000 [range:tcp_port] type = tcp local_ip = 127.0.0.1 local_port = 80,443 remote_port = 8080,8443
Author
Owner

@GhostLee commented on GitHub (Nov 7, 2021):

我也有这个需求。。。。
由于远端服务器配置很弱,没有部署nginx,远端服务器A上只存在frps,监听来自外部的http或https请求,同时将监听到的请求转发给本地Nginx服务器B,本地Nginx服务器再根据自己的规则配置解析到不同的本地服务上。
现在使用的是监听80、443 tcp端口的方式,无法获取到用户的真实IP、无法使用Cloudflare的防护功能。
想知道有没有更优雅的方式来实现这种远端转发,本地解析的形式。
感谢各位大佬

<!-- gh-comment-id:962636383 --> @GhostLee commented on GitHub (Nov 7, 2021): 我也有这个需求。。。。 由于远端服务器配置很弱,没有部署nginx,远端服务器A上只存在frps,监听来自外部的http或https请求,同时将监听到的请求转发给本地Nginx服务器B,本地Nginx服务器再根据自己的规则配置解析到不同的本地服务上。 现在使用的是监听80、443 tcp端口的方式,无法获取到用户的真实IP、无法使用Cloudflare的防护功能。 想知道有没有更优雅的方式来实现这种远端转发,本地解析的形式。 感谢各位大佬
Author
Owner

@BackT0TheFuture commented on GitHub (Nov 8, 2021):

@GhostLee
你这完全用反了,nginx是一个功能强大的反代和webserver,有完备的安全、限流等等功能,而且如果仅仅用作反代和静态文件服务,占用内存也是很少的,frp应该放在反代后面,不应该直接对外暴露

<!-- gh-comment-id:962779885 --> @BackT0TheFuture commented on GitHub (Nov 8, 2021): @GhostLee 你这完全用反了,nginx是一个功能强大的反代和webserver,有完备的安全、限流等等功能,而且如果仅仅用作反代和静态文件服务,占用内存也是很少的,frp应该放在反代后面,不应该直接对外暴露
Author
Owner

@GhostLee commented on GitHub (Nov 8, 2021):

晓得了晓得了,我把nginx推到最外层,感谢大佬指正

<!-- gh-comment-id:962782612 --> @GhostLee commented on GitHub (Nov 8, 2021): 晓得了晓得了,我把nginx推到最外层,感谢大佬指正
Author
Owner

@yusanshi commented on GitHub (Nov 8, 2021):

[range:tcp_port]
type = tcp
local_ip = 127.0.0.1
local_port = 80,443
remote_port = 8080,8443

然后外网服务器添加 Nginx 配置(以 443 为例):

server {
    listen 443 ssl;
    server_name subdomain.ccc.com; # 如果要支持所有子域名的话,换成 *.ccc.com
    ssl_certificate ...

    location / {
        proxy_pass https://127.0.0.1:8443;
        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

我大概理解了,但是配置还是不会,运行不起来。达不到效果。

确实只需要 HTTP/HTTPS 转发就好。目的就是把内网服务器里面的网站全部给映射到外网上。

内网服务器(做web服务器) 192.168.0.50 外网服务器(就是做个转发) 55.55.55.55 域名 *.ccc.com 已经指向了该外网服务器,该域名的SSL也已经部署好了

我的内外网服务器都安装了宝塔,2台frp都正常启动了。 需求是外网访问子域名 https://a1.ccc.com 可以访问到内网服务器上的网站(内网服务器上也同样设置1个这样的域名a1.ccc.com的网站)。 至于主域名可以不用,IP也可以不用。

外网服务器的frps配置 [common] bind_addr = 0.0.0.0 bind_port = 7000 bind_udp_port = 7001

外网的 Nginx 配置 配置了反向代理按上面的教程

内网服务器的frpc配置 [common] server_addr = 55.55.55.55 server_port = 7000

[range:tcp_port] type = tcp local_ip = 127.0.0.1 local_port = 80,443 remote_port = 8080,8443

可以检查一下外网和内网服务器 Nginx 的日志:比如可以开两个终端分别连接两个服务器,tail -f /var/log/nginx/access.log,然后浏览器访问 https://a1.ccc.com,检查两个日志是否都有实时输出,看看问题出在哪一步。

另外,Nginx 默认的日志没有记录 Host header,可能不便于 debug,可以在 nginx.conf 里给两个 Nginx 的日志都加上 $http_host,比如这样:

        log_format main '$http_host $remote_addr - $remote_user [$time_local] '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent"';
        access_log /var/log/nginx/access.log main;
<!-- gh-comment-id:962892022 --> @yusanshi commented on GitHub (Nov 8, 2021): > > ``` > > [range:tcp_port] > > type = tcp > > local_ip = 127.0.0.1 > > local_port = 80,443 > > remote_port = 8080,8443 > > ``` > > > > > > > > > > > > > > > > > > > > > > > > 然后外网服务器添加 Nginx 配置(以 443 为例): > > ``` > > server { > > listen 443 ssl; > > server_name subdomain.ccc.com; # 如果要支持所有子域名的话,换成 *.ccc.com > > ssl_certificate ... > > > > location / { > > proxy_pass https://127.0.0.1:8443; > > proxy_set_header Host $host; > > proxy_set_header X-Real-IP $remote_addr; > > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > > } > > } > > ``` > > 我大概理解了,但是配置还是不会,运行不起来。达不到效果。 > > 确实只需要 HTTP/HTTPS 转发就好。目的就是把内网服务器里面的网站全部给映射到外网上。 > > 内网服务器(做web服务器) 192.168.0.50 外网服务器(就是做个转发) 55.55.55.55 域名 *.ccc.com 已经指向了该外网服务器,该域名的SSL也已经部署好了 > > 我的内外网服务器都安装了宝塔,2台frp都正常启动了。 需求是外网访问子域名 https://a1.ccc.com 可以访问到内网服务器上的网站(内网服务器上也同样设置1个这样的域名a1.ccc.com的网站)。 至于主域名可以不用,IP也可以不用。 > > 外网服务器的frps配置 [common] bind_addr = 0.0.0.0 bind_port = 7000 bind_udp_port = 7001 > > 外网的 Nginx 配置 配置了反向代理按上面的教程 > > 内网服务器的frpc配置 [common] server_addr = 55.55.55.55 server_port = 7000 > > [range:tcp_port] type = tcp local_ip = 127.0.0.1 local_port = 80,443 remote_port = 8080,8443 可以检查一下外网和内网服务器 Nginx 的日志:比如可以开两个终端分别连接两个服务器,`tail -f /var/log/nginx/access.log`,然后浏览器访问 <https://a1.ccc.com>,检查两个日志是否都有实时输出,看看问题出在哪一步。 另外,Nginx 默认的日志没有记录 Host header,可能不便于 debug,可以在 nginx.conf 里给两个 Nginx 的日志都加上 $http_host,比如这样: ``` log_format main '$http_host $remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"'; access_log /var/log/nginx/access.log main; ```
Author
Owner

@github-actions[bot] commented on GitHub (Dec 9, 2021):

Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.

<!-- gh-comment-id:989340065 --> @github-actions[bot] commented on GitHub (Dec 9, 2021): Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.
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#2104
No description provided.