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

**URL:** <https://askemq.com/t/topic/2746>\
**Category:** EMQX\
**Created:** [2022 年8 月 19 日 06:50 UTC](https://askemq.com/t/topic/2746 "2022-08-19T06:50:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

作者： ![heeejianbo](https://askemq.com/user_avatar/askemq.com/heeejianbo/32/36_2.png) [@heeejianbo](https://askemq.com/u/heeejianbo)\
发布日期： [2022 年8 月 19 日 08:19 UTC](https://askemq.com/t/topic/2746/2 "2022-08-19T08:19:32Z")

</div>

有两种方案：

1. WS 可以通过 7 层来获取客户端真实的 ip 和端口，emqx 中需要打开

```auto
## 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 需要打开

```auto
## 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](https://www.jianshu.com/p/cc8d592582c9)

---

_[View the full topic](https://askemq.com/t/topic/2746)._
