User:Noctavian

From ArchWiki
Revision as of 11:41, 8 March 2019 by Noctavian (talk | contribs) (Draft for the update of a section of Pacman/Tips_and_tricks)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Proposed section update using the new nginx config file

See Talk:Pacman/Tips_and_tricks#Use a new nginx.conf for Dynamic reverse proxy cache using nginx for discussion.

Dynamic reverse proxy cache using nginx

nginx can be used to proxy package requests to official upstream mirrors and cache the results to the local disk. All subsequent requests for that package will be served directly from the local cache, minimizing the amount of internet traffic needed to update a large number of computers.

In this example, the cache server will run at http://cache.domain.example:8080/ and store the packages in /srv/http/pacman-cache/.

Install nginx on the computer that is going to host the cache. Create the directory for the cache and adjust the permissions so nginx can write files to it:

 # mkdir /srv/http/pacman-cache
 # chown http:http /srv/http/pacman-cache

Use the nginx pacman cache config as a starting point for /etc/nginx/nginx.conf. Check that the resolver directive works for your needs. In the upstream server blocks, configure the proxy_pass directives with addresses of official mirrors, see examples in the config file about the expected format. Once you are satisfied with the configuration file start and enable nginx.

In order to use the cache each Arch Linux computer (including the one hosting the cache) must have the following line at the top of the mirrorlist file:

/etc/pacman.d/mirrorlist
Server = http://cache.domain.example:8080/$repo/os/$arch
...
Note: You will need to create a method to clear old packages, as the cache directory will continue to grow over time. paccache (which is provided by pacman-contrib) can be used to automate this using retention criteria of your choosing. For example, find /srv/http/pacman-cache/ -type d -exec paccache -v -r -k 2 -c {} \; will keep the last 2 versions of packages in your cache directory.