Nginx #12184
slorber
started this conversation in
Deployment Platforms
Nginx
#12184
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Disclaimer: This guide was initially contributed by @cschanhniem in this PR. We, Docusaurus maintainers, do not use Nginx and did not test/review it.
This discussion is community-driven. If you think this guide is wrong, could be improved, or is not up to date, please comment below.
Deploying with Nginx
Deploying your Docusaurus site behind Nginx is a common choice for self-hosted deployments. Nginx is a high-performance HTTP server and reverse proxy that excels at serving static files.
Building your site
Before deploying, you need to build your Docusaurus site:
The static files will be generated in the
builddirectory.Basic Nginx configuration
Here is a minimal Nginx configuration to serve a Docusaurus site with client-side routing support. Create a file at
/etc/nginx/sites-available/docusaurus(or equivalent path for your system), replacingyour-domain.comwith your actual domain and/path/to/buildwith the absolute path to yourbuilddirectory:Enabling the site
Client-side routing
The key directive
try_files $uri $uri/ /index.htmlensures that client-side routing works correctly. When a user navigates to a path like/docs/intro, Nginx first checks if a corresponding static file exists ($uri), then checks for a directory ($uri/), and finally falls back toindex.htmlso Docusaurus's React router can handle the route.Enabling HTTPS with Let's Encrypt
For production, enable HTTPS using Certbot:
Certbot will automatically modify your Nginx configuration to serve HTTPS. Your final configuration will use port 443 with SSL certificates.
Gzip compression
Enable Gzip to reduce bandwidth usage. Add these lines to your
nginx.confor within thehttpblock:Advanced configuration
For a more robust setup with HTTPS, security headers, and compression:
Serving from a subpath
If your site is configured with a
baseUrllike/docs/, adjust thetry_filesdirective accordingly:Docker deployment
You can deploy with Docker using the official Nginx image:
Build and run:
docker build -t docusaurus-site . docker run -d -p 80:80 docusaurus-siteBeta Was this translation helpful? Give feedback.
All reactions