# 创建GitHub Pages网站

您可以在新仓库或现有仓库中创建 GitHub Pages 站点。

## 为站点创建仓库

可以为站点创建存储库或选择现有存储库。

如果存储库中并非所有文件都与站点相关，且要为存储库创建 GitHub Pages 站点，则能够为站点配置发布源。 例如，可以使用专用分支和文件夹来保存站点源文件，也可以使用自定义 GitHub Actions 工作流来生成和部署站点源文件。 若要将GitHub Actions用作GitHub Pages的发布源，网站管理员必须为GitHub Actions启用GitHub Enterprise Server。 有关详细信息，请参阅 [为 GitHub Enterprise Server 启用 GitHub Actions](/zh/enterprise-server@3.22/admin/managing-github-actions-for-your-enterprise/enabling-github-actions-for-github-enterprise-server)。

如果要在现有存储库中创建站点，请跳至[创建站点](#creating-your-site)。

1. 在任何页面的右上角，选择 <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-plus" aria-label="Create something new" role="img"><path d="M7.75 2a.75.75 0 0 1 .75.75V7h4.25a.75.75 0 0 1 0 1.5H8.5v4.25a.75.75 0 0 1-1.5 0V8.5H2.75a.75.75 0 0 1 0-1.5H7V2.75A.75.75 0 0 1 7.75 2Z"></path></svg>，然后单击“新建存储库”。

   ![GitHub 下拉菜单的屏幕截图，其中显示了用于创建新项的选项。 菜单项“新建存储库”用深橙色框标出。](/assets/images/help/repository/repo-create-global-nav-update.png)

2. 使用“所有者”下拉菜单选择你想要拥有存储库的帐户。
   ![新 GitHub 存储库的所有者菜单的屏幕截图。 菜单显示两个选项：“octocat”和“github”。](/assets/images/help/repository/create-repository-owner.png)

3. 输入仓库的名称和说明（可选）。 如果要创建用户或组织站点，则存储库必须命名为 `<user>.github.io` 或 `<organization>.github.io`。 如果您的用户或组织名称包含大写字母，您必须小写字母。
   有关详细信息，请参阅“[什么是 GitHub Pages?](/zh/enterprise-server@3.22/pages/getting-started-with-github-pages/what-is-github-pages#types-of-github-pages-sites)”。
   ![存储库中 GitHub Pages 设置的屏幕截图。 存储库名称字段包含文本“octocat.github.io”，并用深橙色框出。](/assets/images/help/pages/create-repository-name-pages.png)

4. 选择仓库可见性。 有关详细信息，请参阅“[关于仓库](/zh/enterprise-server@3.22/repositories/creating-and-managing-repositories/about-repositories#about-repository-visibility)”。

5. 将 **README** 切换为 **开启**。

6. 单击“创建存储库”。

## 创建站点

必须先在 GitHub 上有站点的仓库，然后才可创建站点。 如果未在现有存储库中创建站点，请参阅[为站点创建存储库](#creating-a-repository-for-your-site)。> \[!WARNING]

> 如果站点管理员已启用公共页面， GitHub Pages 则网站在 Internet 上公开可用，即使站点的存储库是专用的还是内部的。 如果站点的存储库中有敏感数据，你可能想要在发布前删除数据。 有关详细信息，请参阅 [为企业配置GitHub页面](/zh/enterprise-server@3.22/admin/configuring-settings/configuring-user-applications-for-your-enterprise/configuring-github-pages-for-your-enterprise#enabling-public-sites-for-github-pages) 和 [关于仓库](/zh/enterprise-server@3.22/repositories/creating-and-managing-repositories/about-repositories#about-repository-visibility)。

1. 在 GitHub 上，导航到站点的仓库。
2. 确定要使用的发布源。 请参阅“[为您的 GitHub Pages 网站配置发布源](/zh/enterprise-server@3.22/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site)”。
3. 为站点创建入口文件。 GitHub Pages 将查找 `index.html`、`index.md` 或 `README.md` 文件，作为站点的入口文件。

   如果发布源是分支和文件夹，则入口文件必须位于源分支上源文件夹的顶层。 例如，如果发布源是 `/docs` 分支上的 `main` 文件夹，则入口文件必须位于名为 `/docs` 的分支上的 `main` 文件夹。

   如果发布源是 GitHub Actions 工作流，则部署的项目必须在项目的顶层包含入口文件。 可以选择使用 GitHub Actions 工作流在工作流运行时生成入口文件，而不是将入口文件添加到存储库。
4. 配置发布源。 请参阅“[为您的 GitHub Pages 网站配置发布源](/zh/enterprise-server@3.22/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site)”。

## 查看已发布的站点

1. 在仓库名称下，单击 <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-gear" aria-label="gear" role="img"><path d="M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z"></path></svg>“Settings”\*\*\*\*。 如果看不到“设置”选项卡，请选择“<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-kebab-horizontal" aria-label="kebab horizontal icon" role="img"><path d="M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"></path></svg>”下拉菜单，然后单击“设置”。

   ![存储库标头的屏幕截图，其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。](/assets/images/help/repository/repo-actions-settings.png)1. 在边栏的“代码和自动化”部分中，单击“<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-browser" aria-label="browser" role="img"><path d="M0 2.75C0 1.784.784 1 1.75 1h12.5c.966 0 1.75.784 1.75 1.75v10.5A1.75 1.75 0 0 1 14.25 15H1.75A1.75 1.75 0 0 1 0 13.25ZM14.5 6h-13v7.25c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25Zm-6-3.5v2h6V2.75a.25.25 0 0 0-.25-.25ZM5 2.5v2h2v-2Zm-3.25 0a.25.25 0 0 0-.25.25V4.5h2v-2Z"></path></svg> Pages”\*\*\*\*。
2. 若要查看已发布的网站，请在“GitHub Pages”下单击“<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-link-external" aria-label="link-external" role="img"><path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg> Visit site”\*\*\*\*。

> \[!NOTE]
> 对站点的更改在推送到 GitHub 后，最长可能需要 10 分钟才会发布。 如果一小时后仍然在浏览器中看不到 GitHub Pages 站点更改，请参阅 [关于 GitHub Pages 站点的 Jekyll 构建错误](/zh/enterprise-server@3.22/pages/setting-up-a-github-pages-site-with-jekyll/about-jekyll-build-errors-for-github-pages-sites)。> \[!NOTE]
>
> * 如果你将从分支发布，并且你的站点没有自动发布，请确保拥有管理员权限和经过验证的电子邮件地址的人已将其推送到发布源。
> * 由使用 `GITHUB_TOKEN` 的 GitHub Actions 工作流推送的提交不会触发 GitHub Pages 生成。

## 静态站点生成器

GitHub Pages 会发布您推送到仓库的任何静态文件。 您可以创建自己的静态文件或使用静态站点生成器为您构建站点。 您还可以在本地或其他服务器上自定义自己的构建过程。

如果使用自定义生成过程或 Jekyll 以外的静态站点生成器，可以编写 GitHub Actions 工作流来生成和发布站点。 GitHub 为多个静态站点生成器提供工作流模板。 有关详细信息，请参阅“[为您的 GitHub Pages 网站配置发布源](/zh/enterprise-server@3.22/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site)”。

如果从源分支发布站点，GitHub Pages 将默认使用 Jekyll 生成站点。 如果想使用 Jekyll 以外的静态站点生成器，则建议编写 GitHub Actions 来生成和发布站点。 否则，通过在发布源的根目录中创建一个名为 `.nojekyll` 的空文件来禁用 Jekyll 生成过程，然后按照静态站点生成器的说明在本地生成站点。

> \[!NOTE] GitHub Pages 不支持服务器端语言，例如 PHP、Ruby 或 Python。

## GitHub Pages 上的 MIME 类型

MIME 类型是服务器发送到浏览器的标头，提供有关浏览器所请求文件性质和格式的信息。 GitHub Pages 支持数千种文件扩展名中 750 多种 MIME 类型。 支持的 MIME 类型列表是从 [mime-db 项目](https://github.com/jshttp/mime-db)生成的。

虽然无法基于每个文件或每个仓库指定自定义 MIME 类型，但您可以添加或修改 MIME 类型以在 GitHub Pages 上使用。 有关详细信息，请参阅 [mime-db 贡献指南](https://github.com/jshttp/mime-db#adding-custom-media-types)。

## 后续步骤

您可以通过创建更多新文件向网站添加更多页面。 每个文件都会在您的网站上以与发布源相同的目录结构提供。 例如，如果项目网站的发布源是 `gh-pages` 分支，并且你在 `/about/contact-us.md` 分支上创建了名为 `gh-pages` 的新文件，该文件将在 `http(s)://<hostname>/pages/<username>/<repository>/about/contact-us.html` 下。

您还可以添加主题以自定义网站的外观。 有关详细信息，请参阅“[使用 Jekyll 向 GitHub Pages 网站添加主题](/zh/enterprise-server@3.22/pages/setting-up-a-github-pages-site-with-jekyll/adding-a-theme-to-your-github-pages-site-using-jekyll)”。

## 其他阅读材料

* [关于 GitHub Pages 和 Jekyll](/zh/enterprise-server@3.22/pages/setting-up-a-github-pages-site-with-jekyll/about-github-pages-and-jekyll)。
* [排查 GitHub Pages 网站的 Jekyll 生成错误](/zh/enterprise-server@3.22/pages/setting-up-a-github-pages-site-with-jekyll/troubleshooting-jekyll-build-errors-for-github-pages-sites)
* [管理存储库中的分支](/zh/enterprise-server@3.22/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository)
* [创建新文件](/zh/enterprise-server@3.22/repositories/working-with-files/managing-files/creating-new-files)
* [排查 GitHub Pages 网站的 404 错误](/zh/enterprise-server@3.22/pages/getting-started-with-github-pages/troubleshooting-404-errors-for-github-pages-sites)