Angular/Sockjs通过Docker+ nginx do
我使用以下命令在 linux 上运行Angular:ng Serve -horst 0.0.0.0 App
[WDS]实时重新加载效果很好。
但是,当我尝试将 Angular 放在代理 nginx 的Docker中时,由于Websocket-connection失败而停止实时重载停止工作:“ get/sockjs-node/034 /gdu0ifc0/websocket http/1.1“ 499(在建立连接之前已关闭WebSocket)
这是我的nginx配置:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name app.local;
location ~* ^/sockjs-node/[0-9]+/[A-Za-z0-9]+/websocket {
resolver 127.0.0.1 valid=30s;
set $front_host http://app_1.localnet;
proxy_pass $front_host:4200;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
location / {
try_files $uri @proxyapp;
}
location @proxyapp {
resolver 127.0.0.11 ipv6=off;
set $dev_container http://app_1.localnet;
proxy_pass $dev_container:4200;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Forwarded "";
}
}
我使用了很多配置说明来修复它,但是没有什么可用的...
我在做什么...我在做什么错误的?)
I run angular on Linux using the following command: ng serve --host 0.0.0.0 app
[WDS] Live Reloading works well.
But when I try to place angular in docker with proxying nginx, Live Reloading stops working because of the websocket-connection failure: "GET /sockjs-node/034/gdu0ifc0/websocket HTTP/1.1" 499 (WebSocket is closed before the connection is established)
Here is my nginx configuration:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name app.local;
location ~* ^/sockjs-node/[0-9]+/[A-Za-z0-9]+/websocket {
resolver 127.0.0.1 valid=30s;
set $front_host http://app_1.localnet;
proxy_pass $front_host:4200;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
location / {
try_files $uri @proxyapp;
}
location @proxyapp {
resolver 127.0.0.11 ipv6=off;
set $dev_container http://app_1.localnet;
proxy_pass $dev_container:4200;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Forwarded "";
}
}
I used a lot of config instructions to fix it, but nothing works...
What am I doing wrong?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于Web插座使用两个HTTP标头(连接和升级),因此您的Websocket连接故障发生了。
添加' proxy_set_header升级$ http_upgrade; '和' proxy_set_header连接$ http_connection; 'to nginx config:
edit:edit:edit:
edit:edity
:
NG服务-Public-Host 0.0.0.0应用
Your websocket-connection failure happens because web sockets use two HTTP headers (Connection and Upgrade).
Add 'proxy_set_header Upgrade $http_upgrade;' and 'proxy_set_header Connection $http_connection;' to your nginx config:
Edit:
Try remove everything and use:
Furthermore, run your app with:
ng serve --public-host 0.0.0.0 app