Nginx 配置 WebSocket 反向代理

在nginx.conf配置添加map指令

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

配置虚拟主机

upstream websocket {
    server 1.2.3.4:80;
}

server {
    listen 80;
    server_name www.123admin.com;

    access_log  /www/log/nginx/www.123admin.com.access.log  main;
    error_log  /var/log/nginx/www.123admin.com.error.log;

    location / {
        proxy_pass http://websocket;
        include proxy.conf;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}