Jekyll部署至GitHub Pages遇404错误求助
Troubleshooting Your Jekyll Portfolio's 404 Error
Hey there, let’s work through that 404 issue on your portfolio site step by step—here are the most common fixes to check first:
1. Verify GitHub Pages Deployment Settings
- Head to your repo’s Settings > Pages section. Double-check that the source is set to the
gh-pagesbranch and the directory is/(root)(unless you configured Jekyll to build into adocsfolder, which is less common for portfolio sites). - Look for the latest deployment status on that same page. If there’s a failed build, click into the details to view the log—GitHub will often flag Jekyll-specific errors (like missing gems, invalid YAML in
_config.yml, or broken front matter) that prevent your site from generating correctly.
2. Fix Your _config.yml BaseURL & URL
This is the #1 culprit for subpath site 404s (since your site lives at /portfolio instead of the root domain):
- Open your
_config.ymland make sure these lines are set correctly:baseurl: "/portfolio" url: "https://linus345.github.io" - Never omit the
baseurlwhen your site is hosted in a repo subpath—Jekyll uses this to generate correct internal links.
3. Audit Internal Links & Permalinks
- All internal links (navigation, images, CSS, page references) should use the
site.baseurlvariable to ensure they point to the right subpath. For example:- Instead of
<a href="/about">About</a>, use<a href="{{ site.baseurl }}/about">About</a> - For images:
<img src="{{ site.baseurl }}/assets/img/photo.jpg" alt="My photo">
- Instead of
- Check your permalink settings in
_config.yml. If you’re using a custom format (likepermalink: /:title/), ensure it doesn’t include absolute paths (e.g.,https://linus345.github.io/aboutis bad—stick to relative paths like/about/).
4. Compare Local Build to GitHub’s gh-pages Branch
- Run
bundle exec jekyll buildlocally to generate the_sitefolder. Inspect its structure: do you see anindex.htmlat the root? Are other pages (likeabout.htmlorprojects/index.html) present? - Compare the contents of your local
_sitefolder to what’s in yourgh-pagesbranch on GitHub. If files are missing or paths differ, it means either:- Your local build has errors you didn’t notice (check the terminal output when running
jekyll build), or - You’re manually uploading source files instead of the built static content (if you’re not using GitHub’s automatic Jekyll build).
- Your local build has errors you didn’t notice (check the terminal output when running
5. Wait for GitHub Pages Propagation
Sometimes, even after a successful build, it can take 5-10 minutes for GitHub Pages to fully propagate changes. If you just pushed updates, give it a few minutes before reloading the site.
If none of these fix the issue, share a snippet of your _config.yml and an example of a broken link from your site—we can dig deeper!
内容的提问来源于stack exchange,提问作者user6514554
相关产品推荐
相关产品推荐

