Jekyll部署GitHub Pages后资源路径指向localhost问题求助
Hey there! As someone who’s fumbled through Jekyll’s config quirks as a beginner, let’s walk through how to get those links pointing to your live GitHub Pages site instead of localhost. Since you mentioned updating _config.yml, let’s start by verifying those settings, then cover the other common gotchas that trip up new users.
1. Double-Check Your _config.yml Core Settings
The two most critical values here are url and baseurl—make sure they’re configured perfectly for your repo:
url: This needs to be your full live site URL. For your case, that’shttps://sebastian3495.github.iobaseurl: Since your repo is the special user/organization site (namedsebastian3495.github.io), this should be an empty string:""
Your config should have lines like this:
url: "https://sebastian3495.github.io" baseurl: ""
If you previously set baseurl to something like /sebastian3495.github.io, that would break links on the live site—so empty is the right call here.
2. Stop Hardcoding Links—Use Jekyll’s Site Variables
The #1 mistake new Jekyll users make is writing hardcoded links like http://localhost:4000/about in templates or markdown files. Instead, always build links using site.url and site.baseurl to ensure they work both locally and on your live site.
Examples of correct link formatting:
- In HTML templates (like
header.htmlorfooter.html):<a href="{{ site.url }}{{ site.baseurl }}/about">About</a> - In markdown posts/pages:
[My About Page]({{ site.url }}{{ site.baseurl }}/about)
Do a full search across your _layouts, _includes, and markdown files to replace any leftover localhost links—they’re easy to miss!
3. Refresh Jekyll’s Cache & Restart Your Server
Jekyll caches old config values and generated files, so even if you updated _config.yml, the old settings might still be loaded. Fix this with these quick steps:
- Stop your running local server (press
Ctrl+Cin your terminal) - Clear cached files:
bundle exec jekyll clean - Restart the server to generate fresh files with your updated config:
bundle exec jekyll serve
Now when you view your local site, links should show your GitHub Pages URL instead of localhost.
4. Verify Deployment to GitHub Pages
After pushing your updated config and templates to GitHub, give Pages a minute to rebuild your site. Once it’s done, check the live site—all links should now point to https://sebastian3495.github.io instead of localhost.
If you still see issues, double-check for any hidden hardcoded links (they sometimes hide in _config.yml’s permalink settings or custom template variables). A full repo search for localhost will help you catch any stragglers.
内容的提问来源于stack exchange,提问作者John Nielsen

