Use this file to discover all available pages before exploring further.
Docusaurus generates a folder of static files that can be hosted anywhere a web server can serve HTML. After running the build command, you copy the output to your host of choice — Docusaurus itself has no runtime server-side component.
Before deploying, compile your source files into static output:
npm run build
The generated files land in build/. You can verify the output locally before uploading:
npm run serve
This serves build/ at http://localhost:3000 and is the closest approximation of production you can run on your machine.
Make sure url and baseUrl in docusaurus.config.js match your deployment target before building. Incorrect values cause broken asset paths and wrong canonical URLs.
GitHub Pages is free for all public repositories and is built into every GitHub account. The docusaurus deploy command automates the entire process: it builds the site and pushes the output to the deployment branch in one step.
1
Configure docusaurus.config.js
Add the three required fields for GitHub Pages deployment:
For an organization root site (repo named my-org.github.io), use baseUrl: '/' and omit projectName or set it to the repo name.
2
Prevent Jekyll processing
GitHub Pages runs files through Jekyll by default, which strips files whose names begin with _. Add an empty .nojekyll file to your static/ directory to disable this:
The command clones the repo, builds the site, commits the output to the gh-pages branch, and pushes.
GitHub requires a personal access token (PAT) instead of a password for command-line authentication. When prompted for a password, enter your PAT. Alternatively, set USE_SSH=true to authenticate over SSH instead.
4
Automate with GitHub Actions (optional)
Add this workflow file to trigger a deployment on every push to main:
Log in to Netlify, click Add new site, connect your Git repository, and set:
Build command:npm run build
Publish directory:build
3
Disable Pretty URLs
Netlify’s Pretty URLs feature rewrites paths to lowercase and adds trailing slashes, which conflicts with Docusaurus’s routing. In your Netlify site settings, go to Post Processing → Asset Optimization and uncheck Pretty URLs independently — the global “Disable asset optimization” checkbox does not affect it.
4
Handle monorepos (if applicable)
If your docs/ folder sits outside the Docusaurus root, add a custom ignore command so Netlify triggers builds when docs change:
Vercel automatically detects Docusaurus and preconfigures build settings for you, including preview deployments for every branch and pull request.
1
Push your site to a Git repository
Vercel’s Git integration reads from GitHub, GitLab, or Bitbucket. Make sure your project is pushed to one of these providers.
2
Import the project into Vercel
In the Vercel dashboard, click Add New → Project, find your repository, and click Import. Vercel will auto-detect the Docusaurus framework and pre-fill:
Framework preset: Docusaurus
Build command:npm run build
Output directory:build
3
Deploy
Click Deploy. Vercel builds the site and assigns a .vercel.app subdomain. Every future push to the production branch (usually main) triggers a production deployment. Pushes to other branches create preview URLs automatically.
For full control over server configuration, deploy the build/ directory to your own server using a static file server, Nginx, or Apache.
1
Build the site
npm run build
2
Serve with docusaurus serve
For a quick self-hosted option, Docusaurus ships its own serve command:
npm run serve -- --build --port 80 --host 0.0.0.0
docusaurus serve is convenient for testing but is not recommended for production. Use a CDN or a hardened reverse proxy like Nginx instead.
3
Serve with Nginx
Copy the build/ directory to your server’s web root and add an Nginx virtual host:
/etc/nginx/sites-available/my-site
server { listen 80; server_name docs.example.com; root /var/www/my-site/build; index index.html; location / { try_files $uri $uri/ /index.html; }}
Free for public repos. Straightforward if your code is already on GitHub. The docusaurus deploy command and the GitHub Actions workflow handle everything automatically.
Netlify
Easiest setup overall. Generous free tier, automatic preview URLs for pull requests, and one-click rollbacks. Best for teams who want zero infrastructure work.
Vercel
Excellent performance and developer experience. Auto-detects Docusaurus. Preview deployments and edge caching on the free plan.
Self-hosted
Full control over server configuration, redirects, authentication, and custom middleware. Most complex to maintain, but the only option when data cannot leave your infrastructure.
docusaurus.config.js is the only file that runs in Node.js during the build — MDX pages and React components are client-side and cannot read process.env directly. Pass environment variables through customFields: