Why Use a Reverse Proxy?
A reverse proxy provides several benefits:- SSL/TLS Encryption: Secure your CAD with HTTPS
- Custom Domains: Use friendly domain names instead of IP:port
- Load Balancing: Distribute traffic across multiple instances
- Caching: Improve performance with static asset caching
- Security: Hide your server’s real IP and ports
Prerequisites
- SnailyCAD installed and running (Docker or Standalone)
- A domain name pointing to your server
- Port 80 and 443 open on your firewall
- Root or sudo access to your server
nginx Setup
Installation
Install Certbot for SSL
Install Certbot to obtain free SSL certificates from Let’s Encrypt:Ubuntu/Debian:RHEL/CentOS/Fedora:
Create nginx configuration
Create a new configuration file for SnailyCAD:Add the following configuration:
Replace
cad.yourdomain.com and api.yourdomain.com with your actual domain names.Enable the configuration
Create a symbolic link to enable the site:Test the configuration:If successful, reload nginx:
Obtain SSL certificates
Use Certbot to obtain and install SSL certificates:Follow the prompts to:
- Enter your email address
- Agree to the terms of service
- Choose whether to redirect HTTP to HTTPS (recommended)
- Obtain SSL certificates
- Update your nginx configuration
- Set up automatic certificate renewal
nginx Configuration Explained
Key directives in the nginx configuration:client_max_body_size 50M: Allows file uploads up to 50MBproxy_set_header Host $host: Preserves the original host headerproxy_set_header X-Real-IP $remote_addr: Passes the client’s real IPproxy_set_header X-Forwarded-Proto $scheme: Indicates HTTPS was usedproxy_http_version 1.1: Required for WebSocket supportproxy_set_header Upgrade $http_upgrade: Enables WebSocket upgrades
Caddy Setup
Caddy is a modern web server with automatic HTTPS.Installation
Create Caddyfile
Edit the Caddy configuration:Add the following configuration:
Replace
cad.yourdomain.com and api.yourdomain.com with your actual domains.Reload Caddy
Reload Caddy to apply the configuration:Caddy will automatically:
- Obtain SSL certificates from Let’s Encrypt
- Configure HTTPS
- Set up HTTP to HTTPS redirects
- Handle certificate renewals
Caddy Advantages
- Automatic HTTPS: No need to manually configure SSL certificates
- Simple Configuration: Minimal syntax compared to nginx
- Modern Defaults: HTTP/2, OCSP stapling enabled by default
- Zero Downtime Reloads: Configuration changes don’t interrupt traffic
Single Domain Setup
If you prefer to use a single domain with paths instead of subdomains:nginx (Single Domain)
Caddy (Single Domain)
.env:
Troubleshooting
502 Bad Gateway
Verify SnailyCAD is running:SSL Certificate Errors
Check certificate validity:WebSocket Connection Failed
Ensure these headers are set in your nginx configuration:CORS Errors
Verify your.env URLs match exactly:
CORS_ORIGIN_URLshould matchNEXT_PUBLIC_CLIENT_URL- Include the protocol (
https://) - Don’t include trailing slashes
Security Best Practices
nginx Security Headers
Add these headers to your nginx configuration:Firewall Configuration
Block direct access to SnailyCAD ports:Rate Limiting
Add rate limiting to prevent abuse: nginx:Next Steps
Docker Installation
Set up SnailyCAD with Docker
Standalone Installation
Install SnailyCAD without Docker