[GH-ISSUE #2029] nginx http2的问题 #1611

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

Originally created by @imlizi on GitHub (Oct 13, 2020).
Original GitHub issue: https://github.com/fatedier/frp/issues/2029

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.

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)?
0.34.1

What operating system and processor architecture are you using (go env)?
centos 8.2

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build670955070=/tmp/go-build -gno-record-gcc-switches"

Configures you used:
frps.ini

[common]
bind_port=7000
vhost_http_port = 7001
vhost_https_port = 7002

frpc.ini

[common]
server_port = 8001
tcp_mux = true
[web]
type = https
local_ip = 127.0.0.1
local_port = 443
custom_domains = a.com

服务器nginx配置

{
listen 443 ssl http2;
server_name a.com;
location / {
    proxy_ssl_server_name on;
    proxy_pass https://imabsn.com:8005;
    proxy_set_header Host $host;
    proxy_set_header Remote-Addr $remote_addr;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

内网nginx

{
listen 443 ssl http2;
server_name a.com;
root /demo;
}

Describe the results you received:
内网机器上的nginx日志里,看到请求都是 http1.1

Describe the results you expected:
nginx日志里应该是http2才对

Additional information you deem important (e.g. issue happens only occasionally):

Can you point out what caused this issue (optional)

Originally created by @imlizi on GitHub (Oct 13, 2020). Original GitHub issue: https://github.com/fatedier/frp/issues/2029 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. 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)?** `0.34.1` **What operating system and processor architecture are you using (`go env`)?** `centos 8.2` ``` GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/root/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/golang" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build670955070=/tmp/go-build -gno-record-gcc-switches" ``` **Configures you used:** `frps.ini` ``` [common] bind_port=7000 vhost_http_port = 7001 vhost_https_port = 7002 ``` `frpc.ini` ``` [common] server_port = 8001 tcp_mux = true [web] type = https local_ip = 127.0.0.1 local_port = 443 custom_domains = a.com ``` 服务器nginx配置 ``` { listen 443 ssl http2; server_name a.com; location / { proxy_ssl_server_name on; proxy_pass https://imabsn.com:8005; proxy_set_header Host $host; proxy_set_header Remote-Addr $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ``` 内网nginx ``` { listen 443 ssl http2; server_name a.com; root /demo; } ``` **Describe the results you received:** 内网机器上的nginx日志里,看到请求都是 http1.1 **Describe the results you expected:** nginx日志里应该是http2才对 **Additional information you deem important (e.g. issue happens only occasionally):** **Can you point out what caused this issue (optional)**
gitea-mirror 2026-05-05 13:01:42 -06:00
  • closed this issue
  • added the
    invalid
    label
Author
Owner

@fatedier commented on GitHub (Oct 13, 2020):

请确认下访问的客户端是否使用的 HTTP2 协议请求?

<!-- gh-comment-id:707477198 --> @fatedier commented on GitHub (Oct 13, 2020): 请确认下访问的客户端是否使用的 HTTP2 协议请求?
Author
Owner

@imlizi commented on GitHub (Oct 13, 2020):

image
用Firefox看,是http2,然而内网的日志还是http1.1

<!-- gh-comment-id:707478209 --> @imlizi commented on GitHub (Oct 13, 2020): ![image](https://user-images.githubusercontent.com/30803070/95815467-51bf4880-0d4f-11eb-8f89-f5fecc47d9fd.png) 用Firefox看,是http2,然而内网的日志还是http1.1
Author
Owner

@fatedier commented on GitHub (Oct 13, 2020):

对于 HTTPS 代理来说,frp 不会修改连接的任何内容,建议可以控制变量,尝试直接连接 nginx 或者使用 TCP 类型的代理来测试。

<!-- gh-comment-id:707511171 --> @fatedier commented on GitHub (Oct 13, 2020): 对于 HTTPS 代理来说,frp 不会修改连接的任何内容,建议可以控制变量,尝试直接连接 nginx 或者使用 TCP 类型的代理来测试。
Author
Owner

@imlizi commented on GitHub (Oct 13, 2020):

对于 HTTPS 代理来说,frp 不会修改连接的任何内容,建议可以控制变量,尝试直接连接 nginx 或者使用 TCP 类型的代理来测试。

没明白是什么意思? 😳

<!-- gh-comment-id:707527656 --> @imlizi commented on GitHub (Oct 13, 2020): > 对于 HTTPS 代理来说,frp 不会修改连接的任何内容,建议可以控制变量,尝试直接连接 nginx 或者使用 TCP 类型的代理来测试。 没明白是什么意思? 😳
Author
Owner

@fatedier commented on GitHub (Oct 13, 2020):

通过控制变量法来做测试、调试,验证和找到可能的问题点在哪里。

<!-- gh-comment-id:707532086 --> @fatedier commented on GitHub (Oct 13, 2020): 通过控制变量法来做测试、调试,验证和找到可能的问题点在哪里。
Author
Owner

@imlizi commented on GitHub (Oct 13, 2020):

通过控制变量法来做测试、调试,验证和找到可能的问题点在哪里。

我在外网nginx里加上

proxy_http_version 1.1;

内网的nginx日志是http1.1, 如果不加,就是 http1.0, 跟这个有关系吗?

<!-- gh-comment-id:707533144 --> @imlizi commented on GitHub (Oct 13, 2020): > 通过控制变量法来做测试、调试,验证和找到可能的问题点在哪里。 我在外网nginx里加上 ``` proxy_http_version 1.1; ``` 内网的nginx日志是http1.1, 如果不加,就是 http1.0, 跟这个有关系吗?
Author
Owner

@fatedier commented on GitHub (Oct 13, 2020):

看起来你的问题可能和 frp 无关,建议学习下 nginx 相关的文档吧。

<!-- gh-comment-id:707535642 --> @fatedier commented on GitHub (Oct 13, 2020): 看起来你的问题可能和 frp 无关,建议学习下 nginx 相关的文档吧。
Author
Owner

@imlizi commented on GitHub (Oct 13, 2020):

服务器上的nginx反代我去掉了,直接用frp监听443,可以吧?
nginx反代用http2似乎不太好

# frpc.ini
[web]
type = https
local_port = 443
custom_domains = test.yourdomain.com
# 目前支持 v1 和 v2 两个版本的 proxy protocol 协议。
proxy_protocol_version = v2

这个配置,我加上v2就挂,不加v2就没事。这是怎么回事呢?
image

<!-- gh-comment-id:707556093 --> @imlizi commented on GitHub (Oct 13, 2020): 服务器上的nginx反代我去掉了,直接用frp监听443,可以吧? [nginx反代用http2似乎不太好](https://www.zhihu.com/question/268666424/answer/347026835) ``` # frpc.ini [web] type = https local_port = 443 custom_domains = test.yourdomain.com # 目前支持 v1 和 v2 两个版本的 proxy protocol 协议。 proxy_protocol_version = v2 ``` 这个配置,我加上v2就挂,不加v2就没事。这是怎么回事呢? ![image](https://user-images.githubusercontent.com/30803070/95830740-b89e2b00-0d6a-11eb-803c-3e45c6833530.png)
Author
Owner

@fatedier commented on GitHub (Oct 13, 2020):

proxy_protocol_version 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。

<!-- gh-comment-id:707579402 --> @fatedier commented on GitHub (Oct 13, 2020): `proxy_protocol_version` 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。
Author
Owner

@imlizi commented on GitHub (Oct 13, 2020):

proxy_protocol_version 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。

这个就不纠结了,直接用frps监听443,就OK了,可是获取不到真实IP了。
原先的使用外网的nginx用的是

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

这样内网的nginx日志里可以用 $http_x_real_ip或者 $http_x_forwarded_for 获取到真实ip,现在外网没了nginx的反代了。直接用frp,我看文档 获取用户真实IP 里就是加上了

proxy_protocol_version = v2

为什么我一加就不行呢?

<!-- gh-comment-id:707826936 --> @imlizi commented on GitHub (Oct 13, 2020): > `proxy_protocol_version` 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。 这个就不纠结了,直接用frps监听443,就OK了,可是获取不到真实IP了。 原先的使用外网的nginx用的是 ``` proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; ``` 这样内网的nginx日志里可以用 $http_x_real_ip或者 $http_x_forwarded_for 获取到真实ip,现在外网没了nginx的反代了。直接用frp,我看文档 [获取用户真实IP](https://gofrp.org/docs/features/common/realip/) 里就是加上了 ``` proxy_protocol_version = v2 ``` 为什么我一加就不行呢?
Author
Owner

@Becods commented on GitHub (Oct 16, 2020):

proxy_protocol_version 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。

这个就不纠结了,直接用frps监听443,就OK了,可是获取不到真实IP了。
原先的使用外网的nginx用的是

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

这样内网的nginx日志里可以用 $http_x_real_ip或者 $http_x_forwarded_for 获取到真实ip,现在外网没了nginx的反代了。直接用frp,我看文档 获取用户真实IP 里就是加上了

proxy_protocol_version = v2

为什么我一加就不行呢?

nginx需要有相关的配置

real_ip_header proxy_protocol;
real_ip_recursive on;
set_real_ip_from 0.0.0.0;

个人认为没有必要应用HTTP2到服务器nginx
看了一下nginx代理配置,并无写与HTTP2相关内容
正确配置应加上proxy_http_version 2;

此外,没必要再多套一层nginx或者frp
猜测源拓扑:内网nginx→服务器nginx→frpc→frps
个人推荐拓扑:内网nginx→frpc→frps内网nginx→服务器nginx

<!-- gh-comment-id:710125549 --> @Becods commented on GitHub (Oct 16, 2020): > > `proxy_protocol_version` 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。 > > 这个就不纠结了,直接用frps监听443,就OK了,可是获取不到真实IP了。 > 原先的使用外网的nginx用的是 > > ``` > proxy_set_header X-Real-IP $remote_addr; > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > ``` > > 这样内网的nginx日志里可以用 $http_x_real_ip或者 $http_x_forwarded_for 获取到真实ip,现在外网没了nginx的反代了。直接用frp,我看文档 [获取用户真实IP](https://gofrp.org/docs/features/common/realip/) 里就是加上了 > > ``` > proxy_protocol_version = v2 > ``` > > 为什么我一加就不行呢? nginx需要有相关的配置 ``` real_ip_header proxy_protocol; real_ip_recursive on; set_real_ip_from 0.0.0.0; ``` 个人认为没有必要应用HTTP2到服务器nginx 看了一下nginx代理配置,并无写与HTTP2相关内容 正确配置应加上proxy_http_version 2; 此外,没必要再多套一层nginx或者frp 猜测源拓扑:`内网nginx→服务器nginx→frpc→frps` 个人推荐拓扑:`内网nginx→frpc→frps` 或 `内网nginx→服务器nginx`
Author
Owner

@peaceanddemocracy commented on GitHub (May 30, 2022):

proxy_protocol_version 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。

这个就不纠结了,直接用frps监听443,就OK了,可是获取不到真实IP了。
原先的使用外网的nginx用的是

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

这样内网的nginx日志里可以用 $http_x_real_ip或者 $http_x_forwarded_for 获取到真实ip,现在外网没了nginx的反代了。直接用frp,我看文档 获取用户真实IP 里就是加上了

proxy_protocol_version = v2

为什么我一加就不行呢?

nginx需要有相关的配置

real_ip_header proxy_protocol;
real_ip_recursive on;
set_real_ip_from 0.0.0.0;

个人认为没有必要应用HTTP2到服务器nginx 看了一下nginx代理配置,并无写与HTTP2相关内容 正确配置应加上proxy_http_version 2;

此外,没必要再多套一层nginx或者frp 猜测源拓扑:内网nginx→服务器nginx→frpc→frps 个人推荐拓扑:内网nginx→frpc→frps内网nginx→服务器nginx

这个proxy_protocol的配置在nginx的conf文件中加在哪个位置的?可以给个参考示例么,默认443端口和80端口的

<!-- gh-comment-id:1141118585 --> @peaceanddemocracy commented on GitHub (May 30, 2022): > > > `proxy_protocol_version` 这个和你的需求没有关系,去掉即可,具体是什么作用,可以看文档。 > > > > > > 这个就不纠结了,直接用frps监听443,就OK了,可是获取不到真实IP了。 > > 原先的使用外网的nginx用的是 > > ``` > > proxy_set_header X-Real-IP $remote_addr; > > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > > ``` > > > > > > > > > > > > > > > > > > > > > > > > 这样内网的nginx日志里可以用 $http_x_real_ip或者 $http_x_forwarded_for 获取到真实ip,现在外网没了nginx的反代了。直接用frp,我看文档 [获取用户真实IP](https://gofrp.org/docs/features/common/realip/) 里就是加上了 > > ``` > > proxy_protocol_version = v2 > > ``` > > > > > > > > > > > > > > > > > > > > > > > > 为什么我一加就不行呢? > > nginx需要有相关的配置 > > ``` > real_ip_header proxy_protocol; > real_ip_recursive on; > set_real_ip_from 0.0.0.0; > ``` > > 个人认为没有必要应用HTTP2到服务器nginx 看了一下nginx代理配置,并无写与HTTP2相关内容 正确配置应加上proxy_http_version 2; > > 此外,没必要再多套一层nginx或者frp 猜测源拓扑:`内网nginx→服务器nginx→frpc→frps` 个人推荐拓扑:`内网nginx→frpc→frps` 或 `内网nginx→服务器nginx` 这个proxy_protocol的配置在nginx的conf文件中加在哪个位置的?可以给个参考示例么,默认443端口和80端口的
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#1611
No description provided.