Nginx:WebSocket的X-Forwarded-For替代方案是什么?

Nginx:WebSocket的X-Forwarded-For替代方案是什么?,nginx,websocket,Nginx,Websocket,在使用WebSocket时,是否有任何方法将客户端标识传递给Nginx(以获得粘性会话)?类似于HTTP的“X-Forwarded-For”标头的东西?WebSocket在HTTP升级握手下开始其生命。握手成功完成后,您将恢复长时间运行的双向websocket连接 如果使用Nginx作为websockets的代理,那么也可以使用“X-Forwarded-for”,但只能在握手时使用。例如,见: 。。。和一些参考资料 您可以配置Nginx在升级请求中应发送的内容(用于标识客户端的信息),后端服务器

在使用WebSocket时,是否有任何方法将客户端标识传递给Nginx(以获得粘性会话)?类似于HTTP的“X-Forwarded-For”标头的东西?

WebSocket在HTTP升级握手下开始其生命。握手成功完成后,您将恢复长时间运行的双向websocket连接

如果使用Nginx作为websockets的代理,那么也可以使用“X-Forwarded-for”,但只能在握手时使用。例如,见:

。。。和一些参考资料

您可以配置Nginx在升级请求中应发送的内容(用于标识客户端的信息),后端服务器的工作是使用握手中的信息标识客户端,然后将websocket连接与客户端关联。基于该关联,该websocket连接上出现的任何消息都属于先前标识的客户端

# WebSocket Proxy
#
# Simple forwarding of unencrypted HTTP and WebSocket to a different host
# (you can even use a different host instead of localhost:8080)

server {
    listen 80;

    # host name to respond to
    server_name ws.example.com;

    location / {
        # switch off logging
        access_log off;

        # redirect all HTTP traffic to localhost:8080
        proxy_pass http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # WebSocket support (nginx 1.4)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}