zeropingheroes / lancache

Automatically cache game files and updates at LAN parties using Nginx as a reverse proxy.
BSD 3-Clause "New" or "Revised" License
61 stars 9 forks source link

LANcache

Automatically cache game files and updates at LAN parties using Nginx as a reverse proxy.

Forked with thanks from Lochnair/lancache

Requirements

Installation

Automatic

Use lancache-installer

Manual

  1. sudo -i
  2. rm -rf /etc/nginx/
  3. git clone https://github.com/zeropingheroes/lancache.git /etc/nginx
  4. cd /etc/nginx
  5. cp .env.example .env
  6. nano .env
  7. ./prepare-configs.sh
  8. systemctl restart nginx

Enabling & Disabling Caches

Simply create and remove symlinks from caches-available/ to caches-enabled

Clearing Cache

To clear the cache, run:

/etc/nginx/scripts/clear-cache.sh

Removing Specific Items From The Cache

It is desirable to remove items from the cache, in case of corruption, or items being cached that shouldn't have been.

Currently there is no straightforward or reliable way to do this, without paying for Nginx Plus.

The closest we can get is to update the cached item from upstream by using the proxy_cache_bypass config option to tell Nginx to re-fetch the item from upstream when it receives the custom request header "X-Cache-Bypass", forcing it to update the item in cache, and serve the updated item to the client. This can be done using the following CURL snippet:

$ export ITEM_TO_RE_REQUEST="http://valve123.steamcontent.com/depot/282440/chunk/d6556e1b9f7?l=14&e=1446464&sid=103124340&h=2da3a7ad94cab11ff1e6aac28"
$ curl --verbose --header "X-Cache-Bypass: 1" "$ITEM_TO_RE_REQUEST" > /dev/null

$ITEM_TO_RE_REQUEST must be set to the full URL, including the original query string, so that Nginx can pass the request on and get a valid response. If Nginx does not get a valid response, the item will not be updated in the cache.

Problems with this approach

Known Issues

Cache Corruption

In the very unlikely event that the cache stores and serves up a corrupted file, only some download clients handle this helpfully for us:

Contributing

Please submit pull requests to useful changes and enhancements.

Recommended reading: Nginx's Caching blog post