![](/img/trans.png)
[英]Firebase Hosting hosted website with custom domain not loading with www prefix
[英]Separate hosting for SPA and Website but share domain
我想分開托管我的應用程序和網站。 層次結構如下:
example.com
- 托管在 DigitalOcean 的網站example.com/*
- SPA 托管在 Firebase Hosting由於 DNS 不允許指向子目錄,有沒有更明智的方法來實現這一點?
提前致謝!
由於子域解決方案不受青睞,您可以嘗試使用像 nginx 這樣的代理來根據到不同后端的路徑來路由流量。 示例配置可能如下所示:
server {
listen ...;
...
location / {
proxy_pass http://<your-website>;
}
location /app {
proxy_pass http://<your-app>;
}
location /another-app {
proxy_pass http://<another-app>;
}
...
}
來源: https : //gist.github.com/soheilhy/8b94347ff8336d971ad0
您可能還想檢查 Digital Ocean 負載均衡器產品是否提供基於路徑的路由。
我最終通過子域解決了這個問題,並決定分享這個解決方法。
1.DNS記錄如下
www : pointing to website
* : root pointing SPA
2. 在我的 Vue 應用程序中,我剛剛添加了一個簡單的window.replace
以從 root 重定向到www
。
if (window.location.host === 'example.com') window.location.replace('https://www.example.com');
——
遠非整潔,但工作得很好:)
我將@Scarysize 的答案標記為解決方案,因為它是一個更全面的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.