[GH-ISSUE #2839] 请教如何获取客户端真实IP #2269

Closed
opened 2026-05-05 13:27:47 -06:00 by gitea-mirror · 7 comments
Owner

Originally created by @smallfish01 on GitHub (Mar 14, 2022).
Original GitHub issue: https://github.com/fatedier/frp/issues/2839

Bug Description

内网web server用的是nginx,在nginx.conf里添加了X-Forwarded-For和X-Real-IP,

然后在frpc.ini设置了proxy_protocol_version,

当用户在外网访问next.domain.com时,在内部nginx日志上还是显示frps 的IP,不知道配置哪里出错了?

谢谢!

frpc Version

0.38.1

frps Version

0.38.1

System Architecture

Linux/amd64

Configurations

内网Nginx.conf:

server {
listen 80 proxy_protocol;
listen [::]:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

server {
listen 443 ssl http2 proxy_protocol;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

frpc.ini

[next]
type = https
local_port = 443
local_ip = 192.168.21.49
custom_domains = next.domain.com
proxy_protocol_version = v2

[next-http]
type = http
local_port = 80
local_ip = 192.168.21.49
custom_domains = next.domain.com
proxy_protocol_version = v2

Logs

No response

Steps to reproduce

...

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @smallfish01 on GitHub (Mar 14, 2022). Original GitHub issue: https://github.com/fatedier/frp/issues/2839 ### Bug Description 内网web server用的是nginx,在nginx.conf里添加了X-Forwarded-For和X-Real-IP, 然后在frpc.ini设置了proxy_protocol_version, 当用户在外网访问next.domain.com时,在内部nginx日志上还是显示frps 的IP,不知道配置哪里出错了? 谢谢! ### frpc Version 0.38.1 ### frps Version 0.38.1 ### System Architecture Linux/amd64 ### Configurations 内网Nginx.conf: server { listen 80 proxy_protocol; listen [::]:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } server { listen 443 ssl http2 proxy_protocol; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } frpc.ini [next] type = https local_port = 443 local_ip = 192.168.21.49 custom_domains = next.domain.com proxy_protocol_version = v2 [next-http] type = http local_port = 80 local_ip = 192.168.21.49 custom_domains = next.domain.com proxy_protocol_version = v2 ### Logs _No response_ ### Steps to reproduce 1. 2. 3. ... ### Affected area - [ ] Docs - [ ] Installation - [ ] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
Author
Owner

@smallfish01 commented on GitHub (Mar 14, 2022):

经过排查,是Nginx配置不对,正确的应该是:
listen 443 ssl http2 proxy_protocol;
real_ip_header proxy_protocol;
set_real_ip_from 192.168.20.2(frp_server_IP);

但是还有个问题,内网有一台web server用的是IIS,我在frpc.ini里配置了proxy_protocol_version = v2后在外网就无访问该服务器,请问这是什么原因,要如何才能在iis服务器的日志上获取客户端访问的真实IP?
谢谢!

<!-- gh-comment-id:1066581716 --> @smallfish01 commented on GitHub (Mar 14, 2022): 经过排查,是Nginx配置不对,正确的应该是: listen 443 ssl http2 proxy_protocol; real_ip_header proxy_protocol; set_real_ip_from 192.168.20.2(frp_server_IP); 但是还有个问题,内网有一台web server用的是IIS,我在frpc.ini里配置了proxy_protocol_version = v2后在外网就无访问该服务器,请问这是什么原因,要如何才能在iis服务器的日志上获取客户端访问的真实IP? 谢谢!
Author
Owner

@Becods commented on GitHub (Mar 16, 2022):

配置proxy_protocol之后web服务端只能解析proxy_protocol协议
请另开端口

<!-- gh-comment-id:1068923621 --> @Becods commented on GitHub (Mar 16, 2022): 配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口
Author
Owner

@smallfish01 commented on GitHub (Mar 21, 2022):

配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口

请教下,IIS支持该协议吗,需要怎么配置

<!-- gh-comment-id:1073515065 --> @smallfish01 commented on GitHub (Mar 21, 2022): > 配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口 请教下,IIS支持该协议吗,需要怎么配置
Author
Owner

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

配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口

是开哪边的端口,nginx还是?可以给个配置文件参考下嘛,小白不懂

<!-- gh-comment-id:1141096887 --> @peaceanddemocracy commented on GitHub (May 30, 2022): > 配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口 是开哪边的端口,nginx还是?可以给个配置文件参考下嘛,小白不懂
Author
Owner

@smallfish01 commented on GitHub (Jun 12, 2022):

配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口

是开哪边的端口,nginx还是?可以给个配置文件参考下嘛,小白不懂
Nginx,我上面有配置,您可以看看。

<!-- gh-comment-id:1153102011 --> @smallfish01 commented on GitHub (Jun 12, 2022): > > 配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口 > > 是开哪边的端口,nginx还是?可以给个配置文件参考下嘛,小白不懂 Nginx,我上面有配置,您可以看看。
Author
Owner

@peaceanddemocracy commented on GitHub (Jun 13, 2022):

配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口

是开哪边的端口,nginx还是?可以给个配置文件参考下嘛,小白不懂
Nginx,我上面有配置,您可以看看。

我按照这个设置了,nginx启动报错。。。

<!-- gh-comment-id:1153970411 --> @peaceanddemocracy commented on GitHub (Jun 13, 2022): > > > 配置proxy_protocol之后web服务端只能解析proxy_protocol协议 请另开端口 > > > > > > 是开哪边的端口,nginx还是?可以给个配置文件参考下嘛,小白不懂 > > Nginx,我上面有配置,您可以看看。 我按照这个设置了,nginx启动报错。。。
Author
Owner

@smallfish01 commented on GitHub (Jun 17, 2022):

把你的错误和配置贴出来看看。

<!-- gh-comment-id:1158591277 --> @smallfish01 commented on GitHub (Jun 17, 2022): 把你的错误和配置贴出来看看。
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#2269
No description provided.