[GH-ISSUE #1591] frp 使用 Proxy Protocol 转发 tcp 流到 nginx http 监听端口时 浏览器访问失败 #1259

Closed
opened 2026-05-05 12:48:13 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @Thonnn on GitHub (Jan 3, 2020).
Original GitHub issue: https://github.com/fatedier/frp/issues/1591

Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly.
(为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。)
(请不要在 issue 评论中出现无意义的 加1我也是 等内容,将会被直接删除。)
(由于个人精力有限,和系统环境,网络环境等相关的求助问题请转至其他论坛或社交平台。)

Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST

What version of frp are you using (./frpc -v or ./frps -v)?
谢谢,以下是我使用的frp版本信息:
frps: 0.22.0
frpc: 0.31.0

What operating system and processor architecture are you using (go env)?
全是 centos7.4。
nginx 正常编译,确认包含 http、stream、http-realip-module、stream-realip-module等等。
经测试 nginx 自身转发自身 proxy_protocol 正常,理论上说,nginx 的 proxy_protocol 加载应该是没有问题的。

Configures you used:
frps.ini:

[common]
bind_port = 7068
bind_udp_port = 7061

frpc.ini

[common]
server_addr = frp.mydomain
server_port = 7068
admin_addr = 192.168.18.11
admin_port = 100
admin_user = admin
admin_pwd = admin

[tcp11]
type = tcp
local_ip = 192.168.18.11
local_port = 98
remote_port = 7066
proxy_protocol_version = v2

....

Steps to reproduce the issue:

  1. 客户端192.168.18.11电脑上使用 nginx 开启98号端口。
  2. nginx http节点主要配置如下:
server{
        listen  98 proxy_protocol;
        server_name     ~^(?<num1>\d+)\.(?<num2>\d+)\.frp\.mydomain$;
        real_ip_header  proxy_protocol;
        client_max_body_size        10G;
        set $thost '192.168.18.11';
        if ($num1 = '11'){
                set $thost '127.0.0.1';
        }
        if ($num1 != '11'){
                set $thost '192.168.18.$num1';
        }
        location / {
                proxy_set_header Cache-Control no-store;
                proxy_set_header Host $host:7066;
                proxy_set_header X-Real-IP $proxy_protocol_addr;
                proxy_set_header X-Forwarded-For $proxy_protocol_addr;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_pass http://$thost:$num2;
        }
}
  1. 启动nginx,frp,chrome访问http://101.7074.frp.mydomain

Describe the results you received:
浏览器显示:
微信截图_20200103173159

有些时候浏览器只给出 ERR_EMPTY_RESPONSE 的提示

nginx错误日志:

2020/01/03 17:29:48 [error] 19958#0: *3 broken header: "GET /login.html HTTP/1.1
Host: 101.7074.frp.mydomain:7066
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close

" while reading PROXY protocol, client: 192.168.18.11, server: 0.0.0.0:98

Describe the results you expected:

背景
这么干的原因是,通过tcp流转发实现内网穿透,frp将tcp流转发给nginx http监听端口,继而进行分发。将其部署在一台本地电脑上,通过nginx解析域名格式,实现网段内所有主机http转发。
之所以使用tcp流,是因为实际请求域名由三部分构成:网段ip.端口.frp域名,同时这台服务器的7066、7067等多个端口都在做这个事情,其承担着公司好几个分公司网络穿透的责任。

需求
我程序需要捕获http请求来源的ip地址,参考frp文档,设置 proxy_protocol_version 参数,对于所有tcp都可以支持,http自然也是基于tcp的,但是发现不太可行。不知道是哪里的问题。

Additional information you deem important (e.g. issue happens only occasionally):
从 nginx 的日志看,请求的头解析出错,意味着可能frp的转发过程中,proxy_protocol 的头设置的有问题。只是不知道问题出在什么地方,frp本身还是我的设置。
同时 nginx 将配置 listen 98 proxy_protocol; 改为 listen 98; 其他配置包括frp配置均不变的情况下,可以正常访问正常使用,只是无法捕获来源ip,程序给的结果是nginx 和 frp 所在的主机内网地址 192.168.18.11
希望该可以得到解决。

Can you point out what caused this issue (optional)
对frp原理和代码不熟,抱歉。

再次感谢FRP。

Originally created by @Thonnn on GitHub (Jan 3, 2020). Original GitHub issue: https://github.com/fatedier/frp/issues/1591 Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly. (为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。) (请不要在 issue 评论中出现无意义的 **加1**,**我也是** 等内容,将会被直接删除。) (由于个人精力有限,和系统环境,网络环境等相关的求助问题请转至其他论坛或社交平台。) Use the commands below to provide key information from your environment: You do NOT have to include this information if this is a FEATURE REQUEST **What version of frp are you using (./frpc -v or ./frps -v)?** 谢谢,以下是我使用的frp版本信息: frps: 0.22.0 frpc: 0.31.0 **What operating system and processor architecture are you using (`go env`)?** 全是 centos7.4。 nginx 正常编译,确认包含 http、stream、http-realip-module、stream-realip-module等等。 经测试 nginx 自身转发自身 proxy_protocol 正常,理论上说,nginx 的 proxy_protocol 加载应该是没有问题的。 **Configures you used:** frps.ini: ``` [common] bind_port = 7068 bind_udp_port = 7061 ``` frpc.ini ``` [common] server_addr = frp.mydomain server_port = 7068 admin_addr = 192.168.18.11 admin_port = 100 admin_user = admin admin_pwd = admin [tcp11] type = tcp local_ip = 192.168.18.11 local_port = 98 remote_port = 7066 proxy_protocol_version = v2 .... ``` **Steps to reproduce the issue:** 1. 客户端192.168.18.11电脑上使用 nginx 开启98号端口。 2. nginx **http**节点主要配置如下: ```conf server{ listen 98 proxy_protocol; server_name ~^(?<num1>\d+)\.(?<num2>\d+)\.frp\.mydomain$; real_ip_header proxy_protocol; client_max_body_size 10G; set $thost '192.168.18.11'; if ($num1 = '11'){ set $thost '127.0.0.1'; } if ($num1 != '11'){ set $thost '192.168.18.$num1'; } location / { proxy_set_header Cache-Control no-store; proxy_set_header Host $host:7066; proxy_set_header X-Real-IP $proxy_protocol_addr; proxy_set_header X-Forwarded-For $proxy_protocol_addr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_pass http://$thost:$num2; } } ``` 3. 启动nginx,frp,chrome访问`http://101.7074.frp.mydomain` **Describe the results you received:** 浏览器显示: ![微信截图_20200103173159](https://user-images.githubusercontent.com/29172396/71716331-4b5e8080-2e4f-11ea-9d23-77d5f100f538.png) 有些时候浏览器只给出 `ERR_EMPTY_RESPONSE` 的提示 nginx错误日志: ``` log 2020/01/03 17:29:48 [error] 19958#0: *3 broken header: "GET /login.html HTTP/1.1 Host: 101.7074.frp.mydomain:7066 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Connection: close " while reading PROXY protocol, client: 192.168.18.11, server: 0.0.0.0:98 ``` **Describe the results you expected:** **背景** 这么干的原因是,通过tcp流转发实现内网穿透,frp将tcp流转发给nginx http监听端口,继而进行分发。将其部署在一台本地电脑上,通过nginx解析域名格式,实现网段内所有主机http转发。 之所以使用tcp流,是因为实际请求域名由三部分构成:网段ip.端口.frp域名,同时这台服务器的7066、7067等多个端口都在做这个事情,其承担着公司好几个分公司网络穿透的责任。 **需求** 我程序需要捕获http请求来源的ip地址,参考frp文档,设置 `proxy_protocol_version` 参数,对于所有tcp都可以支持,http自然也是基于tcp的,但是发现不太可行。不知道是哪里的问题。 **Additional information you deem important (e.g. issue happens only occasionally):** 从 nginx 的日志看,请求的头解析出错,意味着可能frp的转发过程中,proxy_protocol 的头设置的有问题。只是不知道问题出在什么地方,frp本身还是我的设置。 同时 nginx 将配置` listen 98 proxy_protocol;` 改为 ` listen 98;` 其他配置包括frp配置均不变的情况下,可以正常访问正常使用,只是无法捕获来源ip,程序给的结果是nginx 和 frp 所在的主机内网地址 `192.168.18.11` 希望该可以得到解决。 **Can you point out what caused this issue (optional)** 对frp原理和代码不熟,抱歉。 再次感谢FRP。
Author
Owner

@fatedier commented on GitHub (Jan 5, 2020):

frps 也需要升级到最新版本。

<!-- gh-comment-id:570844251 --> @fatedier commented on GitHub (Jan 5, 2020): frps 也需要升级到最新版本。
Author
Owner

@Thonnn commented on GitHub (Jan 5, 2020):

frps 也需要升级到最新版本。

谢谢 已解决,我以为只用改客户端来着,多谢

<!-- gh-comment-id:570873838 --> @Thonnn commented on GitHub (Jan 5, 2020): > frps 也需要升级到最新版本。 谢谢 已解决,我以为只用改客户端来着,多谢
Author
Owner

@keepingcoding commented on GitHub (Nov 24, 2023):

请问怎么解决的

<!-- gh-comment-id:1825931521 --> @keepingcoding commented on GitHub (Nov 24, 2023): 请问怎么解决的
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#1259
No description provided.