就没有用nginx转发ws/wss配置proxy_protocol获取真实IP的案例吗

环境信息

  • EMQX 版本:4.3
  • 操作系统及版本:
  • 其他

问题描述

照着网上的教程nginx配置proxy_protocol加emqx打开proxy_protocol=on,结果死活就是连不上ws

配置文件及日志

image

有两种方案:

  1. WS 可以通过 7 层来获取客户端真实的 ip 和端口,emqx 中需要打开
## Specify which HTTP header for real source IP if the EMQX cluster is          
## deployed behind NGINX or HAProxy.                                            
##                                                                              
## Default: X-Forwarded-For                                                     
## listener.ws.external.proxy_address_header = X-Forwarded-For                  
                                                                                
## Specify which HTTP header for real source port if the EMQX cluster is        
## deployed behind NGINX or HAProxy.                                            
##                                                                              
## Default: X-Forwarded-Port                                                    
## listener.ws.external.proxy_port_header = X-Forwarded-Port     

然后,你的 LB 需要把客户端真实的 IP 和 端口 用这两个 http 头发送过来

  1. 使用三层的 proxyo protocol, emqx 需要打开
## Enable the Proxy Protocol V1/2 if the EMQ cluster is deployed behind         
## HAProxy or Nginx.                                                            
##                                                                              
## See: listener.ws.$name.proxy_protocol                                        
##                                                                              
## Value: on | off                                                              
## listener.ws.external.proxy_protocol = on 

然后,你的 lb 需要支持用 proxy-protocol 连接 emqx 例如 https://www.jianshu.com/p/cc8d592582c9