3
我想讓webpack-dev-server
在Docker容器中運行,然後通過NGINX主機訪問它。加載初始的index.html
,但與開發服務器的Web套接字連接無法連接。使用NGINX proxy_pass的Webpack開發服務器
VM47:35 WebSocket連接到 'WS://example.com/sockjs-node/834/izehemiu/websocket' 失敗:WebSocket的握手期間錯誤:意外響應代碼:400
我使用下面的配置。
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream webpack_dev_server {
server node;
}
server {
server_name _;
listen 80;
root /webpack_dev_server;
location/{
proxy_pass http://webpack_dev_server;
}
location /sockjs-node/ {
proxy_pass http://webpack_dev_server/sockjs-node/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host; # pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass
proxy_http_version 1.1; # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
# WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
我在HTTPS服務器的情況下工作了一些,並且遇到了一些問題,並解決了這些問題並在此處發佈了答案:http://stackoverflow.com/questions/43081342/webpack-dev-server-with- nginx的代理通換HTTPS -domain-causes-neterr-conne這將有助於其他人通過這篇文章。 – JoelParke