Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy Protocol 无法使用 #26

Closed
sansi98h opened this issue Dec 2, 2024 · 13 comments
Closed

Proxy Protocol 无法使用 #26

sansi98h opened this issue Dec 2, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@sansi98h
Copy link

sansi98h commented Dec 2, 2024

这是nginx的提示,使用frp的Proxy Protocol 可以正常使用

不管是V1、V2还是关闭,均为以下日志

image

这是npc的日志,使用的是docker安装
image

这是nps的配置

image

@sansi98h sansi98h added the bug Something isn't working label Dec 2, 2024
@djylb
Copy link
Owner

djylb commented Dec 2, 2024

服务端是最新版吗?要是最新版还有问题的话提供一下Nginx配置,没问题的话直接关闭问题就行。

@sansi98h
Copy link
Author

sansi98h commented Dec 2, 2024

服务端是最新版吗?要是最新版还有问题的话提供一下Nginx配置,没问题的话直接关闭问题就行。

服务器、客户端都是最新版的(0.26.31),这是Nginx配置
image

我前端为haproxy或者frp,开启Proxy Protocol 可以正常使用

@djylb
Copy link
Owner

djylb commented Dec 2, 2024

我这边用nginx/1.27.1做后端,使用NPS的TCP转发开启Proxy Protocol V1和V2测试都没问题。
测试使用的Nginx配置:

server {
	listen 85 proxy_protocol;
	location / {
	    add_header Content-Type text/plain;
	    return 200 "Client IP: $proxy_protocol_addr\n";
	}
}
server {
	listen 86 ssl proxy_protocol;
        ssl_certificate     /etc/ssl/xxx.pem;
        ssl_certificate_key /etc/ssl/xxx.key;
	location / {
	    add_header Content-Type text/plain;
	    return 200 "Client IP: $proxy_protocol_addr\n";
	}
}

效果:
Snipaste_2024-12-02_18-09-02

@djylb
Copy link
Owner

djylb commented Dec 2, 2024

对了NPS只支持自身向后端通过Proxy Protocol传递真实IP,不支持其他前置反向代理传入Proxy Protocol,如果前置代理已经传递了Proxy Protocol的话NPS要关掉这个才行。
如果你方便的话抓包看一下头部具体什么情况,或者提供具体NPS和NGINX的组合方式,我这边需要复现这个问题才能修,不过我用上面的配置测试看起来没问题,我更倾向于推测是你的配置问题。

@sansi98h
Copy link
Author

sansi98h commented Dec 2, 2024

对了NPS只支持自身向后端通过Proxy Protocol传递真实IP,不支持其他前置反向代理传入Proxy Protocol,如果前置代理已经传递了Proxy Protocol的话NPS要关掉这个才行。 如果你方便的话抓包看一下头部具体什么情况,或者提供具体NPS和NGINX的组合方式,我这边需要复现这个问题才能修,不过我用上面的配置测试看起来没问题,我更倾向于推测是你的配置问题。

前段就nps,然后就转发到了nginx,haproxy是我本地局域网,为了兼容Proxy Protocol才加的,我也正在找问题

@djylb
Copy link
Owner

djylb commented Dec 2, 2024

有nginx了应该不需要haproxy才对,不知道是不是nginx版本问题,你可以拿我上面的测试配置试试看能不能返回真实IP。

@sansi98h
Copy link
Author

sansi98h commented Dec 2, 2024

image
这样一个架构,你的配置也不行,都过不了协议检验,版本nginx version: nginx/1.26.1

@djylb
Copy link
Owner

djylb commented Dec 2, 2024

奇怪了,你截图一下NPS网页仪表盘页面的版本号吧
我这边测试了完整配置也是正常的。
Nginx:

server {
	listen 8088 proxy_protocol;

	location / {
	    proxy_pass http://172.16.0.6:88;
	    real_ip_recursive on;
	    set_real_ip_from 0.0.0.0/0;
	    real_ip_header proxy_protocol;
	    proxy_set_header X-Real-IP $remote_addr;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}
}

NPS:
Snipaste_2024-12-02_19-11-52
浏览器测试:
Snipaste_2024-12-02_19-05-03

@sansi98h
Copy link
Author

sansi98h commented Dec 2, 2024

image
为什么你有代理到本地选项,我之前是其它版本的nps,我卸载重装试试

@sansi98h
Copy link
Author

sansi98h commented Dec 2, 2024

我好像找到问题了,ya压缩加密打开就不行了
image

@djylb
Copy link
Owner

djylb commented Dec 2, 2024

OK,用TLS端口连的话就没必要开加密了,下一版我修一下这个。

@sansi98h
Copy link
Author

sansi98h commented Dec 2, 2024

这个配置是总配置,无法单独分开,而且,加密或者压缩,任何一个开了好像都不行

@djylb
Copy link
Owner

djylb commented Dec 2, 2024

已修复

@djylb djylb closed this as completed Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants