mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 08:05:49 -06:00
[GH-ISSUE #888] nginx https反向代理到frp https 报 502错误,说说我的解决方法 #700
Labels
No labels
In Progress
WIP
WaitingForInfo
bug
doc
duplicate
easy
enhancement
future
help wanted
invalid
lifecycle/stale
need-issue-template
need-usage-help
no plan
proposal
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/frp#700
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wangxianfeng on GitHub (Aug 12, 2018).
Original GitHub issue: https://github.com/fatedier/frp/issues/888
首先声明,这不是个问题贴,而是给出了解决方法。看到很多人使用nginx https转发frp https的时候都像我一样,遇到了nginx报502错误的问题,在网上找了一圈,也没有找到解决方式。经过一段时间的摸索,解决了自己的问题,把解决方法分享出来,以求像我一样遇到该问题的人能够快速地解决自己的问题。
What version of frp are you using (./frpc -v or ./frps -v)?
0.20.0
What operating system and processor architecture are you using (
go env)?[root@host frp]# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build188604123=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
Configures you used:
frps.ini关键配置
frpc.ini关键配置:
Steps to reproduce the issue:
nginx https关键配置:
Describe the results you received:
对于nginx https代理frp https的理解
我的理解是这样的:
如果使用了自定义域名,frp是根据$host值判断该往哪个内网服务转发请求的,因此转给frp的请求中一定要包含$host,否则frp无法正常处理请求。
因此以下2个配置很重要:
proxy_pass中不能写成IP的形式。
nginx反向代理frp缓存加速http+https 可以参考我的博文,已经根据最新的理解做了更新。
http://www.wangxianfeng.cn/wordpress/2018/06/10/nginx%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86frp%e7%bc%93%e5%ad%98%e5%8a%a0%e9%80%9fhttphttps/
有什么不对的地方,还请各位指正。
@yflwz commented on GitHub (Apr 15, 2019):
我按上面的配置了,
location / {
proxy_ssl_server_name on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host:$server_port;
proxy_pass https://$host:10053;
}
只是用https://自定义域名访问不了,用https://自定义域名:端口可以
@wangxianfeng commented on GitHub (Apr 15, 2019):
可以看看nginx及frp的日志排查一下
@662 commented on GitHub (Feb 4, 2020):
注意:
$host是你客户端访问的主机头,也即是*.aiuyo.com你只是把
https://*.aiuyo.com代理到了https://*.aiuyo.com:8643相当于你任然是访问的https://*.aiuyo.com:8643,而一旦防火墙不开放8643你这个配置就挂了,因为你的反向代理是到公网去找DNS解析IP;你这个配置并没有达到 网内直达
https://127.0.0.1:8643;如果
frps真的是直接拿的request url而不是拿的http header的话,你这个方法倒是可行,只不过需要修改本地hosts让 本地解析*.aiuyo.com;@662 commented on GitHub (Feb 4, 2020):
我用
0.20(lede只有这个版本) 测试了一下,https反代确实是拿的url,http header里头的主机头直接被无视了,这或许是个bug。 @fatedier@cnyasin commented on GitHub (Mar 19, 2020):
成功!感谢楼主!特来回复!
@Eminlin commented on GitHub (Jun 23, 2020):
搜了整个互联网 , 只有你这个解决了问题 ,感谢分享:)
@wangxianfeng commented on GitHub (Jun 24, 2020):
很欣慰我的分享帮助了一些人
@ggboypro commented on GitHub (Jun 23, 2021):
用了楼主的方法也不行,加上了 resolver 8.8.8.8; 就通了
@569258yin commented on GitHub (Oct 17, 2021):
说的太对了,【而一旦防火墙不开放
8643你这个配置就挂了,因为你的反向代理是到公网去找DNS解析IP】这个确实无法解析host 导致无法查询,需要在防火墙开启端口才可以
@lysssssss commented on GitHub (Jan 21, 2022):
感谢方法,同时也遇到了另一个坑,如果要代理爱快https的话,记得加上proxy_http_version 1.1; 否则静态资源会404
@baiyz0825 commented on GitHub (Jan 6, 2023):
查看日志确实是解析不到域名的问题,加上解析就可以

但是配置了缓存的话,不知道为什么静态文件访问不到了
@baiyz0825 commented on GitHub (Jan 6, 2023):
检查之后还是需要添加一个resolver来进行解析,就跟https://github.com/fatedier/frp/issues/888#issuecomment-945082729这条描述一样,楼主在博客中添加了相应的解析,issues上面没有粘贴全,然后我出现的缓存无法命中或者无法生成原因是因为
所以如果需要强制开启缓存需要增加
之后可以设置请求头
add_header Nginx-Cache “$upstream_cache_status”;检查是否命中缓存完整配置如下:
其余优化:源自segment
爱快代理开启页面缓存产生的404问题
原因未知:这里新增加一个server模块可以解决
@GodFox commented on GitHub (Dec 31, 2023):
我也通过这个方法搞定了,感谢!
@kbitlive commented on GitHub (Feb 7, 2024):
感谢 此方法有效
@JackShi1991 commented on GitHub (Jun 28, 2024):
感谢,确实有效。
@JackShi1991 commented on GitHub (Jun 28, 2024):
我没有域名,只有公网IP,相同配置下其他都正常,只有爱快和青龙面板502,测试加上了proxy_http_version 1.1 后爱快倒是能打开,但是页面卡点了半天没反应。不太懂这些搜了几个网上的教程又加了两行代码,可以了,分享下:
##proxy_pass 要对应http或https