[英]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.