-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve integration with cloud static website hosting #12607
Labels
Milestone
Comments
depp
added a commit
to depp/hugo
that referenced
this issue
Jun 18, 2024
This new configuration parameter causes paths matching "<dir>/index.html" to be stored as "<dir>/" remotely. This simplifies the cloud configuration needed for some use cases, such as CloudFront distributions with S3 bucket origins. Before this change, users must configure their S3 buckets as public websites (which is incompatible with certain authentication / authorization schemes), or users must add a CloudFormation function to add index.html to the end of incoming requests. After this change, users can simply use an ordinary CloudFront distribution (no additional code) with an ordinary S3 bucket origin (and not an S3 website). This adds tests to ensure that functionality like matchers is unaffected by this change. I have also tested that the functionality works as expected when deploying to a real S3 / CloudFront website. Closes gohugoio#12607
@vangent ... does the above match your world view? |
I do not have any expertise in web site hosting, but the explanation sounds plausible and the proposed solution doesn't sound too hard. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Proposal: Add an option to remap files named
<dir>/index.html
to<dir>/
during deployment.Background
Traditional web servers (e.g. Apache, nginx) are typically configured to serve
index.html
files when users visit a directory. However, blob storage systems (e.g. S3, GCS) let you create files with names ending in/
, and this is sometimes preferred.For example, let’s say you deploy your site to an S3 bucket and CloudFront distribution. The simplest way to do this is to just use an S3 origin for your CloudFront distribution. However, this simple setup doesn’t work with Hugo out of the box—your website root
/
will correctly map to the rootindex.html
file, but subdirectories will not work. You will get a 404 error fordir/
, because CloudFront will look for an S3 object nameddir/
instead ofdir/index.html
.There are some workarounds for this:
You can enable “static website hosting” for your S3 bucket, set the index document to
index.html
, and configure CloudFront to use an HTTP origin that points to the S3 bucket. However, this prevents you from using the normal authentication & authorization systems that you would otherwise get, so this option only works for sites that are public.You can use a CloudFront function to remap requests to
dir/
to requestdir/index.html
, but this adds complexity and code to what would otherwise be a no-code configuration. See: https://stackoverflow.com/a/76581267Solution
Add a new option to the
deployment.targets
section of the configuration calledstripIndexHTML
. This option maps any local file named<dir>/index.html
to a remote file named<dir>/
. The root page,index.html
, is untouched.This is “elegant” because this just means that the remote file path matches the canonical URLs that Hugo uses anyways. Your link to
dir/
maps to a remote file nameddir/
.Impact
From a web search, I can see that other people using Hugo have experienced this problem:
The text was updated successfully, but these errors were encountered: