如何配置 --public-host 在 nginx 反向代理后面运行角度通用应用程序?



我想用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进行了以下更改。

索引.html

add <base href="/ssr/"> in <head>

nginx.default.conf

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;
}
}

服务器.ts

const PORT = process.env.PORT || 3604;

相关内容

最新更新