How-to: How to host my static website for free?
How to host my static website for free?
There are many tools to publish your site for free:
- Cloudflare Pages
- Github Pages
- Codeberg Pages
- Gitlab Pages
- Vercel
- Netlify
- Render
And certainly still others.
In any case, you just have to share the content of the web/prod
folder. Here is the way to host your website on Github Pages.
Notes:
- Cloudflare, Vercel, Netlify and Render clone a Github or a Gitlab repository
- Free hosting on Github Pages is only available with a public repository
- I recommend always using a
www
subdomain
Step 1
Order a domain name from your preferred registrar.
Step 2
Configure StaPy with the full host as the base URL for the prod environment:
source
+--- layout
+--- common.json
{
"url.local": "http://localhost:1985/",
"url.prod": "https://www.example.com/"
}
Step 3
We need to tell GitHub Pages our domain name. That can be done by creating a CNAME file containing the domain.
source
+--- assets
+--- CNAME
www.example.com
The CNAME file in the assets
directory will be copied to the website root.
Step 4
Start the StaPy server and crawl all the pages:
python server.py
python tools/crawler.py
Step 5
Create a new public repository named username.github.io
where username is your username on GitHub.
Step 6
Commit and push all the static files on the Github repository.
cd web/prod
git init
git add -A
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/{username}/{repository}.git
git push -u origin main
Step 7
On your Github repository, go to Settings > Pages. Enable Pages for the root directory on the main branch.
Add your custom domain (www.example.com) and enforce HTTPS.
Step 8
From the registrar, edit the DNS zone and add a CNAME record for the www
subdomain:
- Type: CNAME
- Host Name: www
- Points to: username.github.io
- TTL: 1 hour
Next
How to add a new block?
How to add a new blog post?
How to display a list of links?
How to use dynamic data?
How to use Stapy on Windows?
How to host my static website for free?