Creating a Reverse Proxy Site
Create a reverse proxy that forwards requests to a backend application:How Reverse Proxy Works
Upstream Configuration
When you create a reverse proxy, Webinoly automatically creates an upstream configuration in/etc/nginx/conf.d/upstream_proxy.conf:
example.com → example_com).
Proxy Configuration Details
Webinoly’s reverse proxy includes optimized settings:Connection Settings
Header Configuration
Common proxy headers are commented by default. Uncomment in your site configuration as needed:/etc/nginx/sites-available/example.com to customize headers for your application.
WebSocket Support
For WebSocket connections, uncomment:Static File Caching
Reverse proxy sites automatically cache static assets:- Maximum expiration time
- CORS headers enabled
- Access logging disabled
- Optimized delivery
Dedicated Reverse Proxy
For more control over caching, use dedicated reverse proxy mode:- Separate proxy cache zone
- Custom cache control
- Fine-grained cache purging
- Better performance for dynamic backends
Reverse Proxy with Root Path
For applications that need a specific document root for SSL verification:- Let’s Encrypt SSL verification
- Serving static files from the filesystem
- Mixed proxy and static file serving
Common Use Cases
- Node.js Application
- Docker Container
- Python Flask/Django
- Multiple Backend Servers
Running a Node.js app on port 3000:Your Node.js app listens on
127.0.0.1:3000, while NGINX handles:- SSL termination
- Static file caching
- Request buffering
- Connection pooling
Load Balancing Strategies
Edit your upstream configuration for different load balancing methods:SSL with Reverse Proxy
Enable SSL for your reverse proxy site:- Can run on HTTP (no SSL overhead)
- Receives decrypted traffic
- Doesn’t need SSL certificates
Custom Proxy Headers
Edit/etc/nginx/sites-available/example.com to customize proxy headers:
Preserve Original Host
Uncomment to pass the original hostname:Forward Real Client IP
Uncomment to pass client’s real IP:Forward Protocol Information
Uncomment to pass HTTP/HTTPS info:Proxy Cache Configuration
For dedicated reverse proxy with caching:/run/nginx-cache/.
Custom Cache Validity
Skip Cache for Specific Paths
Proxy in Subfolders
Proxy only specific URL paths to a backend:example.com/api/* are proxied to your backend, while other paths can serve static files or use different configurations.
Advanced Configurations
Proxy to External Services
Proxy to external APIs or services:S3 or Cloud Storage Proxy
Proxy to S3-compatible storage:Timeouts and Buffering
Default timeout settings (300 seconds):/etc/nginx/sites-available/example.com.
Error Handling
Proxy configuration includes:proxy_next_upstream to automatically retry failed requests on the next upstream server.
Deleting Reverse Proxy Sites
When you delete a reverse proxy site:- Removes the NGINX configuration
- Deletes the upstream configuration
- Cleans up cache files (if any)
Troubleshooting
Connection Refused
If NGINX shows “connection refused”:-
Verify your backend application is running:
- Check the port number is correct
- Verify firewall allows the connection
502 Bad Gateway
Common causes:- Backend application crashed
- Wrong port number in proxy configuration
- Backend not listening on specified address
- Timeout (increase timeout values)
Headers Not Passed
If your application doesn’t receive expected headers:- Uncomment necessary proxy headers in site configuration
- Verify header names match what your application expects
- Check for header size limits
Best Practices
Security
- Use SSL for production sites
- Keep backends on localhost when possible
- Set appropriate timeouts
- Validate and sanitize headers
Performance
- Enable caching for static assets
- Use keepalive connections
- Configure multiple upstream servers
- Monitor backend response times
Reliability
- Set up multiple backend servers
- Configure health checks
- Use appropriate load balancing
- Enable automatic retry on errors
Monitoring
- Monitor NGINX error logs
- Track upstream status
- Watch for timeout errors
- Set up alerts for failures