This guide will walk you through the process of setting up apt-cacher-ng with Nginx as a reverse proxy to efficiently manage package downloads and updates on your Debian or Ubuntu systems. By implementing apt-cacher-ng, you can significantly reduce the disk space and bandwidth usually required to maintain a local mirror of your Linux packages.
apt-cacher-ng is a caching proxy server for software packages, which stores local copies of any data passed through it from Debian and Ubuntu package repositories. This method ensures that only requested packages are downloaded and stored, reducing unnecessary data transfer and storage space.
Before you begin, ensure you have the following:
Start by installing apt-cacher-ng on your server:
sudo apt update
sudo apt install apt-cacher-ng
Once installed, apt-cacher-ng will automatically start running. You can check the status with:
sudo systemctl status apt-cacher-ng
Edit the main configuration file to tailor the caching behavior:
sudo nano /etc/apt-cacher-ng/acng.conf
Add or modify the following lines to optimize performance and security:
CacheDir: /var/cache/apt-cacher-ng
LogDir: /var/log/apt-cacher-ng
Port:3142
BindAddress: 0.0.0.0
Remap-debrep: file:deb_mirror*.gz /debian ; file:backends_debian
To make apt-cacher-ng accessible via HTTP on port 80, install Nginx and configure it as a reverse proxy:
sudo apt install nginx
sudo nano /etc/nginx/sites-available/apt-cacher-ng
Add the following configuration to the file:
server {
listen 80;
server_name your-server-domain.com;
location / {
proxy_pass http://localhost:3142;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable the site by linking it to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/apt-cacher-ng /etc/nginx/sites-enabled/
Test the Nginx configuration for errors and restart Nginx:
sudo nginx -t
sudo systemctl restart nginx
To direct package downloads through your caching server, configure the apt sources on each client machine:
echo 'Acquire::http { Proxy "http://your-server-domain.com:80"; };' | sudo tee /etc/apt/apt.conf.d/01proxy
This configuration tells the client systems to fetch packages through your apt-cacher-ng setup.
Monitor the performance and cache usage of apt-cacher-ng through its web interface accessible at:
http://your-server-domain.com/acng-report.html
To further enhance your server management and patching strategies, consider visiting:
Visit LinuxPatchFor further details, refer to the official apt-cacher-ng documentation.