【问题标题】:"Page Not Found" when trying to access a site deployed on Netlify尝试访问部署在 Netlify 上的站点时出现“找不到页面”
【发布时间】:2018-11-18 00:36:33
【问题描述】:

我正在运行一个静态的blogdown 站点并将其部署在 Netlify 上。我在 GitHub 上获取文件,Hugo 构建站点,Netlify 部署它。

Netlify 报告该站点处于活动状态(部署日志附在底部),但是当我尝试查看我的站点时,我看到的只是 Netlify 错误消息:

找不到页面

您似乎点击了一个损坏的链接或输入了该网站上不存在的 URL。

←返回我们的网站

可能是什么原因?


我的 GitHub 仓库:https://github.com/taraskaduk/taraskaduk

我的网址应该是网站:https://taraskaduk.com/

我的部署设置:

Repository: https://github.com/taraskaduk/taraskaduk
Build command: hugo
Publish directory: public
Production branch: master
Branch deploys: Deploy only the production branch and its deploy previews
Public deploy logs: Logs are public

雨果版(我试过不同的)

HUGO_VERSION 0.37.1

我最新的部署日志:

9:56:27 PM: Build ready to start
9:56:28 PM: Fetching cached dependencies
9:56:29 PM: Starting to download cache of 172.4MB
9:56:30 PM: Finished downloading cache in 1.74774892s
9:56:30 PM: Starting to extract cache
9:56:33 PM: Finished extracting cache in 2.59393707s
9:56:33 PM: Finished fetching cache in 4.428746301s
9:56:33 PM: Starting to prepare the repo for build
9:56:33 PM: Preparing Git Reference refs/heads/master
9:56:34 PM: Starting build script
9:56:34 PM: Installing dependencies
9:56:35 PM: Started restoring cached node version
9:56:37 PM: Finished restoring cached node version
9:56:37 PM: v8.11.2 is already installed.
9:56:38 PM: Now using node v8.11.2 (npm v5.6.0)
9:56:38 PM: Attempting ruby version 2.3.6, read from environment
9:56:39 PM: Using ruby version 2.3.6
9:56:39 PM: Using PHP version 5.6
9:56:39 PM: Installing Hugo 0.37.1
9:56:39 PM: Started restoring cached go cache
9:56:39 PM: Finished restoring cached go cache
9:56:39 PM: unset GOOS;
9:56:39 PM: unset GOARCH;
9:56:39 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.10.linux.amd64';
9:56:39 PM: export PATH="/opt/buildhome/.gimme/versions/go1.10.linux.amd64/bin:${PATH}";
9:56:39 PM: go version >&2;
9:56:39 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.10.linux.amd64.env';
9:56:39 PM: go version go1.10 linux/amd64
9:56:39 PM: Installing missing commands
9:56:40 PM: Verify run directory
9:56:40 PM: Executing user command: hugo
9:56:40 PM: Building sites …
9:56:40 PM: 
9:56:40 PM:                    | EN
9:56:40 PM: +------------------+----+
9:56:40 PM:   Pages            |  6
9:56:40 PM:   Paginator pages  |  0
9:56:40 PM:   Non-page files   | 49
9:56:40 PM:   Static files     | 39
9:56:40 PM:   Processed images |  0
9:56:40 PM:   Aliases          |  4
9:56:40 PM:   Sitemaps         |  1
9:56:40 PM:   Cleaned          |  0
9:56:40 PM: Total in 522 ms
9:56:40 PM: Caching artifacts
9:56:40 PM: Started saving pip cache
9:56:40 PM: Finished saving pip cache
9:56:40 PM: Started saving emacs cask dependencies
9:56:40 PM: Finished saving emacs cask dependencies
9:56:40 PM: Started saving maven dependencies
9:56:40 PM: Finished saving maven dependencies
9:56:40 PM: Started saving boot dependencies
9:56:40 PM: Finished saving boot dependencies
9:56:40 PM: Started saving go dependencies
9:56:40 PM: Finished saving go dependencies
9:56:40 PM: Build script success
9:56:40 PM: Starting to deploy site from 'public'
9:56:41 PM: Starting post processing
9:56:41 PM: Post processing done
9:56:41 PM: Site is live

【问题讨论】:

  • 您是否尝试将config.toml 中的baseurl 设置为您的网站地址(以斜杠结尾)?我还没有看到导致“页面未找到”的情况,但我看到人们在谈论 it causing other problems
  • 是的,我有。事实上就是这样。我只是尝试将其更改为“/”以查看它是否有任何作用。它没有...
  • 好吧,开枪吧,我没主意了。整个“重定向”线程让我觉得它可能与 index.html 有关,但据我所知,我的 [学术主题网站])github.com/aosmith16/academic) 使用的是同一个线程。希望你能解决问题!
  • 我认为您的问题与重定向无关,因为您没有static/_redirects。我也不认为它与 blogdown 相关,因为它在本地运行良好。我没有像@aosmith这样的想法。您可以联系 Netlify 支持,看看他们是否有任何想法。
  • 其实你可以在Netlify上把hugo的命令改成hugo -v,这样可能会泄露更多信息。

标签: r hugo blogdown netlify


【解决方案1】:

免责声明:我在支持团队 @Netlify 工作

始终允许就此类问题联系 Netlify 支持人员,但我们只能帮助您调试我们的构建过程与您本地的不同之处,而不是调试您的源代码。让我详细介绍一下评论者提出的一些最佳做法,并提供一些建议来帮助您进一步调试不明显的问题。

首先,正如建议的那样(感谢@aosmith!)BaseURL 应该设置为 / - 这是一个最佳实践,将允许您的网站在本地工作 (http://localhost) 也可以在 Netlify 上工作 - 通过 http、https、@ 987654322@,最后在其他托管服务提供商上,同时代理到,等等等等。就这样做:)

其次,您不仅可以在_redirects 文件中进行重定向,还可以在netlify.toml 中进行重定向,但我也不认为这是这里的问题。

当您在主 URL 上收到 404 时,这意味着您没有 /index.html 。根本原因是什么,我不知道(尽管我可以说当您的主题丢失并且可能无法生成您期望的内容时,hugo 不喜欢它)。不过,有两种很好的方法可以找出为什么我们的构建没有在您的发布文件夹中生成 index.html(public,在您的情况下和默认的 hugo 配置):

  1. 您可以从部署日志页面下载任何成功部署的副本,如我的屏幕截图所示,并查看“我们最终得到了什么”。这里的典型问题是我们什么都没有(您的构建没有公开/或者您最终没有 index.html - 所以我们正确地显示了没有路径的 404)

  2. 您可以按照调试说明在本地运行我们的构建映像:https://github.com/netlify/build-image#testing-locally。构建完成后,您仍在构建 shell 中,可以查看发布目录中的内容。

【讨论】:

  • 谢谢@fool!这是一个全面的回应。但是我没有设法自己调试它,重新开始并一步一步地进行。在这里单独发布我的解决方案。
  • 我的错误是创建 index.php 文件而不是 index.html 文件。我不知道 netlify 只提供静态内容。
【解决方案2】:

看来我已经解决了。 我使用示例站点创建了一个新的存储库,并开始用我的部分替换示例站点的部分内容,以查看它何时中断。

所以config.toml 的这一部分必须被排除,以使站点再次正常部署:

[permalinks]
    post = "/:year/:month/:day/:slug/" 

我不知道为什么 - 它一直在那里,当我在本地构建我的网站时它就可以工作,但是一旦我将 public 文件夹添加到 .gitignore 并让 hugo 构建我的网站后就不想工作了。

有什么想法吗?

【讨论】:

【解决方案3】:

如果您使用的是 Angular 8,您需要通过从 angular.json 构建中读取 outputPath(即 dist/{project-name})来提供发布目录值,如果您使用的是旧版本,则它应该是 dist,即outDir 的值,您可以从 .angular-cli.json 中读取。

【讨论】:

    【解决方案4】:

    遇到了这个问题。我的解决方案是为 netlify.toml 文件中的 publish 声明设置正确的构建路径。新的 netlify 自动部署过程使用此文件从存储库部署项目。

    【讨论】:

      【解决方案5】:

      Angular 8 和现在的 Angular 9 在 dist/{project name} 中发布,这是要键入的文件夹名称,而不仅仅是像以前版本中的 dist。如果您仅指定 dist,它将在错误目录中查找 index.html,结果将是“找不到页面”。

      【讨论】:

        【解决方案6】:

        将您的主 HTML 文件命名为 index.html,而不是任何其他名称。

        【讨论】:

          【解决方案7】:

          如果您在直接浏览到特定路径时看到“未找到”错误,例如:https://yourdomain.com/something,这可能会有所帮助(ReactJS):

          在您的 public 文件夹(包含 index.html 的文件夹)中创建一个名为 _redirects 的文件,没有扩展名。然后,在其中输入以下内容:

          /* /index.html 200

          现在保存、提交、推送和发布。 :)

          “未找到”的原因是,当使用路由器时,例如:React Router,它会处理所有路由,但是当您直接转到端点时,netlify 必须知道将您重定向到哪里。这就是我们在_redirects 文件中指定的内容。

          【讨论】:

          • L I F E S A V E R!
          • 我需要这个信息,但你能提供一个示例截图吗?
          • 这真的节省了我的时间,谢谢!但是 Oauth 重定向还有其他一些问题
          【解决方案8】:

          对于 Angular,我遇到了这种情况,我发现以下方法可以工作:

          touch src/_redirects
          
          This file will contain the rule below. It indicates that all requests to the server should be redirected to index.html. We also add a HTTP status code option at the end to indicate that these redirects should return a 200 status. By default, a 301 status is returned.
          
          /*  /index.html 200
          
          The last thing we have to do is add the below option in our angular.json und er projects > {your_project_name} > architect > options > assets. Include it in the assets array:
          
          {
            "glob": "_redirects",
            "input": "src",
            "output": "/"
          }
          

          来自https://www.smashingmagazine.com/2020/10/angular-feedback-netlify-forms-edge/

          【讨论】:

            【解决方案9】:

            我确保“发布目录”和构建文件夹的名称相同。然后我推送了上面@Adwaith 建议的更改。非常感谢@Adwaith,您的意见是救命稻草。

            【讨论】:

              【解决方案10】:

              就我而言,我有(vue3 应用程序)上传整个构建目录(dist/)而不仅仅是文件。这对我有用

              【讨论】:

                【解决方案11】:
                title: 'Tezster Dart',
                  tagline: 'A flutter package which provides the functionalities to play around with tezos dApps',
                  url: 'https://site-name.netlify.app',
                  baseUrl: '/',
                  onBrokenLinks: 'throw',
                  onBrokenMarkdownLinks: 'warn',
                  favicon: 'img/favicon.ico',
                  organizationName: 'Tezsure', // Usually your GitHub org/user name.
                  projectName: 'Tezster_dart', // Usually your repo name.
                

                如果您尚未更新 docs/docusaurus.config.js 中的 url,这可能是个问题。 通过添加url: 'https://site-name.netlify.app', 来修复它,并确保它不以/ 结尾。就我而言,它最终因为/ 而不起作用。

                【讨论】:

                • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
                【解决方案12】:

                在根目录下创建 index.html 并使用以下代码指向 public 文件夹中的索引文件

                <meta http-equiv="Refresh" content="2; url=public/index.html" />
                
                

                【讨论】:

                • 奇怪的是,这就是答案。很惊讶我是 4 个月后的第一个支持者
                猜你喜欢
                • 2019-12-23
                • 2019-05-31
                • 2019-11-20
                • 2019-11-17
                • 2022-12-15
                • 2023-03-15
                • 1970-01-01
                • 1970-01-01
                • 2021-01-10
                相关资源
                最近更新 更多