Overview
Static hosting is ideal for Astro sites because:- Simple Deployment: Just upload the build output
- Low Cost: Many providers offer free hosting for static sites
- High Performance: Serve from CDNs worldwide
- No Server Required: Pure static HTML, CSS, and JavaScript
General Deployment Process
These steps apply to any static hosting provider:Build Your Site
Generate the production build:This creates optimized static files in the
dist/ directory.Upload Files
Upload the contents of the
dist/ directory to your hosting provider.Methods vary by provider:- FTP/SFTP upload
- Git-based deployment
- CLI tools
- Dashboard file upload
Platform-Specific Guides
GitHub Pages
Deploy your portfolio to GitHub Pages for free hosting.Update astro.config.ts
Set the base path for your site:
Omit
base if deploying to yourusername.github.io (user/organization site).GitHub Actions (Automated)
Automate deployment with GitHub Actions:.github/workflows/deploy.yml.
Cloudflare Pages
Deploy to Cloudflare’s global network.Connect Repository
- Log in to Cloudflare Dashboard
- Go to Pages → Create a project
- Connect your Git repository
Configure Build
Set build settings:
- Framework preset: Astro
- Build command:
pnpm run build - Build output directory:
dist - Node version: 18
Cloudflare Pages CLI
GitLab Pages
Deploy using GitLab CI/CD. Create.gitlab-ci.yml:
https://username.gitlab.io/project-name.
Firebase Hosting
Host on Google’s infrastructure.
Your site will be available at
https://project-id.web.app.
AWS S3 + CloudFront
Deploy to Amazon’s cloud infrastructure.Create S3 Bucket
- Log in to AWS Console
- Create an S3 bucket
- Enable static website hosting
- Set public read permissions
Render
Deploy as a static site on Render.Create Static Site
- Log in to Render
- Click New → Static Site
- Connect your repository
Build Configuration
Base Path
If deploying to a subdirectory, set the base path:/my-portfolio.
Environment Variables
For build-time environment variables:Custom Server Configuration
Nginx
If hosting on your own server with Nginx:Apache
For Apache servers, create.htaccess in dist/:
Performance Tips
Enable Compression
Enable Compression
Most hosting providers support gzip/brotli compression. Enable it for faster load times:
- Reduces file sizes by 70-80%
- Automatically supported by CDNs
- Configure in server settings
Configure Caching
Configure Caching
Set proper cache headers:
- HTML: Short cache (1 hour) or no cache
- Assets: Long cache (1 year) with hashed filenames
- Images: Medium cache (1 month)
Use a CDN
Use a CDN
Deploy to a CDN for global performance:
- Cloudflare
- AWS CloudFront
- Fastly
- BunnyCDN
Optimize Images
Optimize Images
Before deploying:Use Astro’s image optimization:
Troubleshooting
404 errors after deployment
404 errors after deployment
Check:
- Files are in the correct directory
basepath is configured correctly inastro.config.ts- Server is configured to serve from the right directory
Assets not loading
Assets not loading
Verify:
siteURL inastro.config.tsmatches your domain- Asset paths are relative or use Astro’s asset handling
- Files exist in the
dist/directory after build
Build succeeds but site is blank
Build succeeds but site is blank
Common causes:
- JavaScript errors (check browser console)
- Incorrect base path configuration
- Missing dependencies in production
Continuous Deployment
Automate deployments with CI/CD:- GitHub Actions: Deploy on every push
- GitLab CI: Built-in pipeline
- Bitbucket Pipelines: Automated builds
- Custom Scripts: Use platform CLIs
Cost Comparison
| Provider | Free Tier | Bandwidth | Build Minutes | Custom Domain |
|---|---|---|---|---|
| GitHub Pages | Yes | 100 GB/month | Unlimited | Yes |
| Cloudflare Pages | Yes | Unlimited | 500/month | Yes |
| Netlify | Yes | 100 GB/month | 300/month | Yes |
| Vercel | Yes | 100 GB/month | 100 hours/month | Yes |
| GitLab Pages | Yes | Unlimited | 400 mins/month | Yes |
| Render | Yes | 100 GB/month | Unlimited | Yes |
Next Steps
Vercel Deployment
Recommended platform with zero-config
Netlify Deployment
Full-featured alternative platform
Styling Guide
Customize your site styling
Configuration
Configure your deployment