A comprehensive demonstration of Varnish Cache's powerful VCL (Varnish Configuration Language) features for high-performance HTTP acceleration and edge computing.
This repository showcases advanced Varnish Cache configurations that demonstrate its capabilities beyond basic HTTP caching. It provides production-ready examples that illustrate Varnish's flexibility as a multi-purpose edge computing platform.
- Intelligent Routing: Direct traffic to appropriate backend servers based on URL patterns, headers, and client properties
- Advanced Caching Strategies: Content-specific TTLs, cache invalidation techniques, and selective caching rules
- Authentication & Security: Basic auth implementation, JWT validation, IP allowlisting, and rate limiting
- Request/Response Manipulation: Header modification, URL normalization, and content transformation
- Load Balancing: Backend health checks and traffic distribution using directors
- Performance Optimisation: Cookie handling, compression, and streaming for large objects
- Edge Logic: Device detection, geo-routing, and A/B testing capabilities
- Monitoring & Debugging: Detailed logging and debug header injection
default.vcl- Main VCL file demonstrating comprehensive capabilities
- Varnish Cache 6.0.x or newer
- VMOD dependencies:
std(included in Varnish)directors(included in Varnish)
-
Install Varnish Cache:
apt-get install varnish # Debian/Ubuntu # or yum install varnish # CentOS/RHEL
-
Install required VMODs:
apt-get install varnish-modules # Most standard modules -
Deploy the configuration:
cp default.vcl /etc/varnish/default.vcl systemctl restart varnish
The main VCL file demonstrates:
| Feature | Section | Description |
|---|---|---|
| Backend Definition | Top | Multiple backend servers with health checks |
| Access Control | ACL | IP-based access restrictions |
| Authentication | authenticate_user |
Basic auth implementation |
| Rate Limiting | vcl_recv |
Request rate controls by client/endpoint |
| Caching Rules | vcl_backend_response |
TTL definitions by content type |
| Device Detection | detect_device |
Mobile vs desktop handling |
| Error Handling | vcl_synth |
Custom JSON error responses |
This configuration is designed to showcase capabilities rather than optimise for a specific workload. When adapting for production:
- Adjust backend connection parameters based on your origin servers' capacity
- Fine-tune TTLs according to your content update frequency
- Optimise memory allocation in
vcl_initbased on expected traffic patterns - Consider backend-specific configurations for heterogeneous infrastructure
Contributions are welcome! Feel free to submit issues and pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
- The Varnish Cache project and community
- Contributors to the Varnish modules ecosystem