摘要:利用nginx反向代理区分流量

代码

  server {
        listen 80;
        server_name www.xxxxx.cf;
        index index.html index.htm index.nginx-debian.html;
        root   /usr/share/nginx/html;        
        location / {  
        #以下是新添加的内容
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        if ($http_upgrade = "websocket") {
            proxy_pass http://127.0.0.1:65534; #shadowsocks-libev配置的port
        }
        }

 }

原理

其原理是将请求头的Upgrade里面的内容,传给变量http_upgrade,这个当http_upgrade的值为websocket时,就走我们配置好的代理

参考链接

https://www.wumingx.com/tools/shadowsocks_obfs.html
https://aber.sh/articles/Fuck-GFW-WebSocket/
http://nginx.org/en/docs/http/websocket.html

参考文档

文章目录