Automatically cache game files and updates at LAN parties using Nginx as a reverse proxy.
Forked from Lochnair/lancache
- Ubuntu 16.04
- A DNS server to redirect clients to the cache
- sniproxy to serve HTTPS requests
Enter an interative superuser shell:
sudo -i
Create the Nginx config directory:
mkdir /etc/nginx && cd /etc/nginx
Clone the zeropingheroes/lancache repository into it:
git clone https://github.com/zeropingheroes/lancache.git .
Make all the scripts in the install directory executable:
chmod -R +x /etc/nginx/install/
Compile Nginx from source:
/etc/nginx/install/compile-nginx.sh
Prepare directories:
/etc/nginx/install/prepare-directories.sh
Install Nginx as a service to start at boot:
/etc/nginx/install/install-nginx-service.sh
Start Nginx:
systemctl start nginx
To limit how much space the cache data folder can use, edit:
includes/proxy-cache-paths.conf
Adjust max_size=1000g
to fit your needs.
ln -s /etc/nginx/caches-available/cache-name.conf /etc/nginx/caches-enabled/cache-name.conf
rm /etc/nginx/caches-enabled/cache-name.conf
To completely clear everything in the cache, run
/etc/nginx/scripts/clear-cache.sh
To find out what's stored in the cache, how much data has been served and which clients have been using the cache, set up Filebeat and ELK to parse logs and show visual statistics.
-
Install Lancache Filebeat configuration file:
/etc/nginx/install/install-filebeat-config.sh
In the very unlikely event that the cache stores and serves up a corrupted file, only some download clients handle this helpfully for us:
- Blizzard - OK - Re-requests the file with headers
Pragma: no-cache
andCache-control: no-cache
which causes Nginx to bypass the cache and request a fresh copy of the file from upstream - Steam - Not OK - Steam will re-request a corrupt file from the cache over and over, but will never send
Pragma: no-cache
andCache-control: no-cache
headers. This causes the game download to never complete - Origin - Not OK - All requests are sent with
Pragma: no-cache
andCache-control: no-cache
and we ignore these or nothing would be cached. If a file is corrupt in the cache there is no mechanism for the Origin client to request Nginx fetches a fresh copy of the file from upstream - Windows Update - Untested
- Riot - Untested
Because we use slice
for these upstreams, Nginx reports a cache hit for almost all requests from clients, as the single client request has spawned one or more subrequests which fill the cache.
If you have a workaround for this behaviour, please submit a pull request.
Please submit pull requests to useful changes and enhancements.
I'd reccomend you read Nginx's Caching blog post to understand caching before diving straight in.
Below are a few ways you can help:
Each cache has two files:
caches-available/cache-name.conf
- Defines basic logging infoupstreams/cache-name.conf
- Defines what should be cached
Duplicate an existing cache's files as a template.
Set the primary server name to lancache-(cachename)
server_name lancache-battletoads;
For all other server names, you must discover each FQDN a content provider uses to serve content and add it to the list of server names.
server_name content1.battletoads.net;
Each location {}
context can either include includes/proxy-cache-upstream.conf
to proxy
and cache the upstream, or include includes/proxy-upstream.conf
to only proxy, and not
cache any content.
Directives in these files can be overriden in the parent configuration
after the include
statement.
location / {
# Load settings to only proxy this upstream location (no caching)
include includes/proxy-upstream.conf;
}
location / {
# Load settings to proxy and cache this upstream location
include includes/proxy-cache-upstream.conf;
# Cache data in the cache named "installers"
proxy_cache installers;