Nginx配置websocket的反向代理web
因爲通常會有跨域問題,就直接把跨域也一併配置了。Nginx的跨域配置詳情能夠參考我以前的文章:Nginx配置跨域請求跨域
websocket的反向代理配置:服務器
直接貼代碼:websocket
server { listen 9000; # 監聽9000端口 server_name websocket_server; # 容許跨域 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; if ($request_method = 'OPTIONS') { return 204; } location / { #添加wensocket代理 proxy_pass http://127.0.0.1:9093; # websocket服務器。不用管 ws:// proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }