3.5 KiB
3.5 KiB
CDN Setup with Nginx and Varnish
This project provides a Bash script to set up and manage a Content Delivery Network (CDN) using Nginx and Varnish. The script offers two main functionalities:
- Install CDN: Configures Varnish and Nginx, sets up SSL certificates with Let's Encrypt, and creates a purge subdomain for cache management.
- Uninstall CDN: Completely removes all configurations and restores the server to its previous state.
Features
- Automatic configuration of Varnish for caching static assets.
- Automated Nginx reverse proxy configuration.
- Let's Encrypt integration for free SSL certificates.
- Cache purge functionality with a randomly generated purge subdomain.
- Uninstall option to clean up all configurations.
Prerequisites
- Ubuntu/Debian-based server
- Root access to the server
- Varnish and Nginx installed
- Certbot for Let's Encrypt SSL certificates
- A valid domain name pointing to the server
Usage
Clone the Repository
git clone https://git.bitmaster.cc/BitMaster/cdn-setup-varnish-nginx.git
cd cdn-setup-varnish-nginx
chmod +x *.sh
Installation
Run the following command to install the CDN configuration:
sudo ./setup-cdn.sh -i
During installation, you will be prompted to:
- Enter the domain and subdomain.
- Confirm whether the source domain uses SSL.
- Specify the cache duration in hours.
- Provide your email for Let's Encrypt SSL certificate issuance.
Uninstallation
To remove all CDN configurations and restore the server:
sudo ./setup-cdn.sh -u
Script Details
Installation Workflow
- Domain validation: Ensures the provided domain is reachable.
- DNS verification: Checks that the subdomain points to the server's IP.
- Varnish configuration: Creates a
.vclfile tailored to the domain. - Nginx configuration: Sets up reverse proxy settings and handles SSL.
- SSL certificate: Uses Certbot to provision and configure SSL.
- Service restarts: Restarts Varnish and Nginx to apply configurations.
Uninstallation Workflow
- Deletes Nginx configuration files.
- Removes the Varnish configuration.
- Restarts all related services to reflect changes.
Example
Installation Example:
sudo ./setup-cdn.sh -i
Sample Input:
Enter your domain (e.g. domain.com): example.com
Enter your subdomain (e.g. cdn): cdn
Does the source domain (example.com) use SSL (HTTPS)? (yes/no): yes
Enter the cache time in hours (e.g. 24): 24
Enter your email for Let's Encrypt notifications: admin@example.com
Uninstallation Example:
sudo ./setup-cdn.sh -u
Sample Input:
Enter the domain to uninstall (e.g. domain.com): example.com
Enter the subdomain to uninstall (e.g. cdn): cdn
Notes
- Ensure that Varnish, Nginx, and Certbot are properly installed and configured before running the script.
- DNS records for the subdomain must be correctly set up and propagated.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
Acknowledgments
Contact
For issues, contact Your Name or open an issue in this repository.