gcloud storage mkdocs 和 index.html 表现不佳

gcloud storage mkdocs and index.html don't play nice

我在 google 云存储上托管由 mkdocs 生成的静态站点。但是,我遇到的错误不应该与该库相关。

我已经设置了我的权限,我可以在

查看网站
https://storage.googleapis.com/<bucketname>/<folder>/index.html

很好,但是无法打开 url:

https://storage.googleapis.com/<bucketname>/<folder>/

它没有识别出它应该抓取 index.html 文件。

这对于索引页面来说不是什么大问题(我可以将用户指向该页面),但对于网站上的所有其他链接来说却是一个大问题。有一个使用此结构生成的子文件夹:

site/planning
├── week1
│   └── index.html
├── week2
│   └── index.html
├── week3
│   └── index.html
└── week4
    └── index.html

google storage docs 分享了一些关于可能发生的事情的线索。但即使在应用他们的建议之后它也不起作用。

> gsutil web set -m index.html gs://<bucketname>/
Setting website configuration on gs://<bucketname>/...

所以我正在寻找解决方案。我的想法是:

  1. 也许 GCloud 不喜欢我没有自己的域名这一事实。这应该很重要,但可能无济于事。
  2. 也许 mkdocs 中有一个设置,使得并非所有内容都是通过 index.html 生成的。
  3. 不为此使用 GCloud 存储,而是使用 github/gitlab 页面或其他内容来托管此静态站点。

非常感谢任何帮助。

在 GCS 部分,此行为在 the docs:

中进行了解释

Website configurations are only used to interpret requests directed to CNAME aliases of c.storage.googleapis.com. (that is, requests where the hostname is a custom domain). For example, only requests to www.example.com show the index page.

Thus, API behavior for requests to Cloud Storage domains, such as storage.googleapis.com/www.example.com, is preserved. For example, you can continue to list objects in the www.example.com bucket as you would for any other bucket. In the case of the www.example.com bucket, the object listing you receive includes 404.html and index.html.

这主要是指通过API地址访问对象时没有重定向或特殊行为,因为这会导致API不一致。

毫无疑问,GCS 中的问题是您没有使用自定义域。

在 mkdocs 部分,use_directory_urls:false 似乎可以解决问题。