[英]How to configure the --public-host to run angular universal app behind nginx reverse proxy?
我想用 HMR 运行一个通用应用程序,我的这个问题是基于它实际上可能的假设。
我已经设置并运行了一个默认的“ng new”angular 8 应用程序并按预期工作。 要在反向代理后面运行它,我正在使用修改后的 npm start 运行
e.g. { "start": "ng serve --host 0.0.0.0 --port 3604 --disable-host-check --public-host //domain.com/spa/sockjs-node/" }
我正在使用 nginx 将 domain.com/spa/sockjs-node/ 路由到 domain.com:3604/sockjs-node
这工作正常,我让 HMR 在 nginx 反向代理后面工作。
我希望与 HMR 一起运行一个有角度的通用应用程序,但我无法弄清楚如何为通用应用程序设置 --public-host //domain.com/universal/sockjs-node/,因为它显然不再使用 ng serve 来运行. 如果没有此设置,则在搜索资产和套接字时不会插入路径的 /universal/ 部分。
所以我在这种情况下的问题是:如何为有角度的通用应用程序设置 --public-host ?
谢谢
对 create-react-app 默认设置和 nginx 进行以下更改。
add <base href="/ssr/"> in <head>
server ...
{
location ^~ /ssr/sockjs-node/ {
proxy_pass http://0.0.0.0:3604/sockjs-node/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ^~ /ssr/ {
proxy_pass http://0.0.0.0:3604/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
const PORT = process.env.PORT || 3604;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.