咨询 frpc 如何获取真实 IP - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
guiyun
V2EX    问与答

咨询 frpc 如何获取真实 IP

  •  
  •   guiyun 331 天前 1439 次点击
    这是一个创建于 331 天前的主题,其中的信息可能已经有所发展或是发生改变。

    各位大佬 我想通过 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 
    14 条回复    2024-11-15 09:15:51 +08:00
    guiyun
        2
    guiyun  
    OP
       331 天前
    @Goooooos 就是按照文档开机 Proxy Protocol 这个功能导致 502 的呀?
    chinanala
        3
    chinanala  
       331 天前
    必须要用 frp 吗?我也有这种需求,不过我是用 haproxy 做四层转发给 nginx ,然后 nginx 配置 proxy_protocol 接收就行了
    opengps
        4
    opengps  
       331 天前
    给 frp 前面的 web ,套一层 cdn ,用 cdn 的那种方式获取 ip 即可
    guiyun
        5
    guiyun  
    OP
       331 天前
    @chinanala 是买的第三方的 frp
    opengps
        6
    opengps  
       331 天前
    或者不用 cdn ,把 nginx 放到最外层,用 nginx 的方式把真实 ip 发给后端
    guiyun
        7
    guiyun  
    OP
       331 天前
    @opengps 别人的 frp,没法在外面套 nginx
    opengps
        8
    opengps  
       331 天前
    谁这么大单敢卖 frp ,但凡你有点违法的东西他不得替你背锅?
    guiyun
        9
    guiyun  
    OP
       331 天前
    @opengps 国内节点,我的还是备案的域名
    opengps
        10
    opengps  
       331 天前
    @guiyun 对方给你提供的是 80/443 端口反向代理?还是你域名跟其他人绑定上去共享了一个 ip 的 80/443 端口?如果是那可能已经套了一层 nginx
    yxhzhang185
        11
    yxhzhang185  
       331 天前
    这个 proxy_protocol_version=v2 也需要在 frps 上配置。
    huaxing0211
        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
    huaxing0211
        13
    huaxing0211  
       330 天前
    另外,在 frp0.6 的示例配置中有:
    requestHeaders.set.x-from-where = "frp",
    它等同于“header_x_forwarded_for = true”,
    所以上述 nignx 配置中,只需要添加那 2 行。
    这是我在 0.6 中的配置,不知道 0.6 以下的版本有何区别,没做研究!
    希望能帮你解决问题!
    guiyun
        14
    guiyun  
    OP
       329 天前
    @huaxing0211
    非常感谢,问题解决了
    老版本也是支持的 配置是 plugin_header_X-From-Where = frp
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2975 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 12:10 PVG 20:10 LAX 05:10 JFK 08:10
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86