各位大佬 我想通过 frp 内网穿透内网的 Nginx, 并且获取真实 IP ,配置如下 我这边一给 nginx 配置 proxy_protocol 这个参数(就在 ssl 后面的这个地方) 网站就是 502.确定反向代理的网站没有错误
我这边有个测试网站 https://test.guiyun.plus
frpc.ini
[TEST_HTTPS] type = https local_ip = 10.0.0.13 local_port = 443 custom_domains = test.guiyun.plus proxy_protocol_version = v2 plugin = https2https plugin_local_addr = 10.0.0.13:443 #证书相关配置 plugin_crt_path = /etc/frp/ssl/_.guiyun.plus.crt plugin_key_path = /etc/frp/ssl/_.guiyun.plus.key plugin_header_X-From-Where = frp
内网 nginx 配置
upstream test { server 127.0.0.1:30080; } server { listen 80; server_name test.guiyun.plus; # 强制跳转到 HTTPS return 301 https://$host$request_uri; } server { # 就在下面这行添加 proxy_protocol 。重启 nginx 后网站就会报 502 。 listen 443 ssl http2 proxy_protocol; server_name test.guiyun.plus; # SSL 证书相关配置,需要自己替换为自己的证书文件路径和密钥文件路径 ssl_certificate ssl/_.guiyun.plus.crt; ssl_certificate_key ssl/_.guiyun.plus.key; location / { proxy_set_header X-Real-IP $proxy_protocol_addr; proxy_set_header X-Forwarded-For $proxy_protocol_addr; proxy_pass http://test; } }
Frpc 的版本是 0.51.2
Nginx 版本是 nginx/1.18.0 编译参数为
Tengine version: Tengine/2.3.3 nginx version: nginx/1.18.0 built by gcc 12.2.0 (Debian 12.2.0-14) built with OpenSSL 1.1.1k 25 Mar 2021 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-pcre=../pcre-8.45 --with-openssl=../openssl-1.1.1k --with-zlib=../zlib-1.2.8 --add-module=../ngx_http_google_filter_module --add-module=../ngx_http_substitutions_filter_module --with-file-aio --with-stream --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug
![]() | 3 chinanala 331 天前 必须要用 frp 吗?我也有这种需求,不过我是用 haproxy 做四层转发给 nginx ,然后 nginx 配置 proxy_protocol 接收就行了 |
![]() | 4 opengps 331 天前 给 frp 前面的 web ,套一层 cdn ,用 cdn 的那种方式获取 ip 即可 |
![]() | 6 opengps 331 天前 或者不用 cdn ,把 nginx 放到最外层,用 nginx 的方式把真实 ip 发给后端 |
![]() | 8 opengps 331 天前 谁这么大单敢卖 frp ,但凡你有点违法的东西他不得替你背锅? |
![]() | 10 opengps 331 天前 @guiyun 对方给你提供的是 80/443 端口反向代理?还是你域名跟其他人绑定上去共享了一个 ip 的 80/443 端口?如果是那可能已经套了一层 nginx |
11 yxhzhang185 331 天前 这个 proxy_protocol_version=v2 也需要在 frps 上配置。 |
12 huaxing0211 330 天前 我用的 0.6 的 frp ,在 nginx 的 server 里加如下内容,即可显示真实 ip ,没做其它设置: real_ip_header X-Forwarded-For; set_real_ip_from 0.0.0.0/0; # 允许任何 IP 段传递真实 IP |
13 huaxing0211 330 天前 另外,在 frp0.6 的示例配置中有: requestHeaders.set.x-from-where = "frp", 它等同于“header_x_forwarded_for = true”, 所以上述 nignx 配置中,只需要添加那 2 行。 这是我在 0.6 中的配置,不知道 0.6 以下的版本有何区别,没做研究! 希望能帮你解决问题! |
14 guiyun OP |