nginx 代理websocket

nginx实现对websocket 反向代理。

    keepalive_timeout  1800;

    map $http_upgrade $connection_upgrade {
		default upgrade;
		''      close;
	}
    
    server {
        listen       80;
        server_name  localhost;
        location / {
            proxy_pass http://192.168.31.96:9001;
            proxy_http_version 1.1;
            echo $http_upgrade;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    
    }

  • keepalive_timeout 多长时间没有读到消息就会关闭的参数,websocket 设置大一点
  • 需要将客户端意图显示的传递给应用服务器proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade;

你可能感兴趣的:(nginx)