如何在 Netlify 上使用相同的自定义域托管多个 Github 存储库? [英] How to host multiple Github repos using the same custom domain on Netlify?

查看:54
本文介绍了如何在 Netlify 上使用相同的自定义域托管多个 Github 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 wjakethompson 使用 Netlify 托管我的个人网站(使用 blogdown 和 Hugo 创建).com.这是通过 Github 存储库部署的.

我现在在单独的存储库中有一个 bookdown 项目,我也想在 Netlify 上托管该项目,同时利用我为我的个人网站设置的自定义域.

目前,这个 bookdown 项目托管在 Netlify 子域(即 wjakethompson-dissertation.netlify.com).但是,我更愿意使用我的自定义域并将第二个存储库托管在 wjakethompson.com/disseration(首选)或 dissertation.wjakethompson.com.这基本上就是 Github 页面所做的(将项目页面作为用户页面的子页面托管),但我发现 Netlify 更容易托管我的个人网页,因此如果可能,我想继续使用 Netlify.

有没有办法使用 Netlify 以这种方式利用自定义域来托管第二个网页?

解决方案

在包含此内容的主存储库中添加 _redirects 文件:

/dissertation/* https://wjakethompson-dissertation.netlify.com/:splat 200

这告诉 Netlify 将请求代理到另一个存储库.但是,您需要确保论文存储库中使用的任何 url 都正确地相对于该路径,这可能很容易,也可能很困难,具体取决于构建系统.

子域替代方案更简单,您不需要做任何特别的事情.只需使用 dissertation.wjakethompson.com 按照自定义域设置进行操作,它应该可以正常工作.https://www.netlify.com/docs/custom-domains/>

子域和主域需要对应同一个Netlify账号下的项目.

I am currently hosting my personal website (created using blogdown and Hugo) using Netlify at wjakethompson.com. This is deployed through a Github repository.

I now have a bookdown project in a separate repository that I would also like to host on Netlify, while leveraging the custom domain that I have set up for my personal website.

Currently, this bookdown project is being hosted on the Netlify subdomin (i.e., wjakethompson-dissertation.netlify.com). However, I would prefer to use my custom domain and have this second repo hosted at wjakethompson.com/disseration (preferred) or dissertation.wjakethompson.com. This is basically what Github pages does (hosting a project page as a subpage of the user page), but I have found Netlify to be much easier for hosting my personal webpage, so would like to continue using Netlify if possible.

Is there a way to host a second webpage leveraging custom domain in this way using Netlify?

解决方案

Add a _redirects file in the the main repo containing this:

/dissertation/* https://wjakethompson-dissertation.netlify.com/:splat 200

This tells Netlify to proxy requests through to the other repo. You will however need to ensure that any urls used in the dissertation repo are correctly relative to this path, which may be easy or may be very hard depending on the build system.

The subdomain alternative is simpler and you don't need to do anything special. Just follow the custom domain setup using dissertation.wjakethompson.com and it should work fine. https://www.netlify.com/docs/custom-domains/

The subdomain and main domain do need to correspond to projects on the same Netlify account.

这篇关于如何在 Netlify 上使用相同的自定义域托管多个 Github 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆