Nginx配置websocket的反向代理

  

由于一般会有跨域问题,就直接把跨域也一并配置了.Nginx的跨域配置详情可以参考我之前的文章:Nginx配置跨域请求

  

websocket的反向代理配置:

  

直接贴代码:

  
 <代码>
  服务器{
  听9000;9000 #监听端口
  server_name websocket_server;
  
  #允许跨域
  add_header Access-Control-Allow-Origin *;
  add_header Access-Control-Allow-Methods“GET、POST、选项”;
  add_header Access-Control-Allow-Headers DNT, X-Mx-ReqToken维生,用户代理,X-Requested-With, if - modified - since, cache - control,内容类型,授权”;
  if ($ request_method='选项'){
  返回204;
  }
  
  位置/{
  #添加wensocket代理
  proxy_pass http://127.0.0.1:9093;# websocket服务器。不用管ws://proxy_http_version 1.1;
  proxy_set_header升级http_upgrade美元;
  proxy_set_header连接“升级”;
  }
  }
   之前

Nginx配置websocket的反向代理