Serve Garry's Mod Content with FastDL and Nginx
Set up FastDL for Garry's Mod with Nginx: bzip2 compression, sv_downloadurl, resource.AddFile, secure publishing, verification, rollback and troubleshooting.
On this page
Your values
Enter them once and the commands in this guide update.
This guide explains how to send your custom content to players through FastDL, from a dedicated Nginx site: preparing the files, compression, publishing, server configuration and rollback.
HostMyServers does not offer managed game hosting: you administer this server yourself on your VPS or dedicated server.
Should You Use FastDL?
| Method | Speed | Use for |
|---|---|---|
Workshop (resource.AddWorkshop) |
Fastest | Any content that can be published on the Workshop, preferred |
FastDL (sv_downloadurl) |
Fast, file by file | Content you cannot publish on the Workshop |
Download from the game server (sv_allowdownload) |
Limited to 64 KB/s | To be avoided |
.lua files are not affected: the game sends them through another mechanism.
How It Works
- The server marks files for download with
resource.AddFile. These files must exist on the game server - The player receives the address set in
sv_downloadurl - For each missing file, they first request the compressed version, then the normal version:
http://fastdl.your-domain.com/materials/my_server/logo.vmt.bz2
http://fastdl.your-domain.com/materials/my_server/logo.vmtThe path on the website must therefore be identical to the path in garrysmod/.
Prerequisites
- A server installed with the Create a Garry's Mod Server guide. This guide builds on its
gmoduser, the/home/gmod/gmod-serverfolder and thegmod.serviceservice - SSH access with
sudo - A subdomain, here
fastdl.your-domain.com, with a DNSArecord pointing to the server's IP address - TCP port 80 available: if another site already uses Nginx on this server, this guide simply adds a separate site
Check the DNS before continuing:
getent hosts fastdl.your-domain.comStep 1: Back Up the Configuration
sudo -u gmod cp -p /home/gmod/gmod-server/garrysmod/cfg/server.cfg /home/gmod/server.cfg.before-fastdl
sudo -u gmod ls -l /home/gmod/server.cfg.before-fastdlStep 2: Install Nginx and bzip2
sudo apt update
sudo apt install -y nginx bzip2Then create the site folder. It belongs to gmod, which publishes the files there, and remains readable by Nginx, which runs as www-data with Debian and Ubuntu packages:
sudo install -d -o gmod -g www-data -m 2750 /var/www/gmod-fastdl /var/www/gmod-fastdl/releases
sudo ls -ld /var/www/gmod-fastdl /var/www/gmod-fastdl/releasesThe permissions displayed must be drwxr-s---, with gmod and www-data as owners.
Step 3: Add Your Content
Your files must exist on the game server. Group them in an addon, following the game's folder structure and using only lowercase:
garrysmod/addons/my_content/
├── materials/my_server/logo.vmt
├── materials/my_server/logo.vtf
├── models/my_server/crate.mdl
└── sound/my_server/announcement.mp3If you uploaded these files to the ~/my_content folder of your administration account, copy them like this:
sudo mkdir -p /home/gmod/gmod-server/garrysmod/addons/my_content
sudo cp -r ~/my_content/. /home/gmod/gmod-server/garrysmod/addons/my_content/
sudo chown -R gmod:gmod /home/gmod/gmod-server/garrysmod/addons/my_contentStep 4: Create the Publishing Script
This script copies the allowed file types, compresses them and publishes everything in a new release. It keeps recent releases so you can roll back.
sudo -u gmod nano /home/gmod/fastdl-sync.sh#!/bin/bash
set -euo pipefail
umask 027
GAME="/home/gmod/gmod-server/garrysmod"
WEB="/var/www/gmod-fastdl"
KEEP=3
# Folders to publish, each organized like garrysmod/
SOURCES=(
"$GAME/addons/my_content"
"$GAME/gamemodes/darkrp/content"
)
NEW="$WEB/releases/$(date +%Y-%m-%d_%H-%M-%S)"
mkdir "$NEW"
for src in "${SOURCES[@]}"; do
[ -d "$src" ] || continue
cd "$src"
for dir in maps materials models particles resource sound; do
[ -d "$dir" ] || continue
find "$dir" -type f \( \
-iname '*.bsp' -o -iname '*.vmt' -o -iname '*.vtf' -o -iname '*.png' -o -iname '*.jpg' \
-o -iname '*.mdl' -o -iname '*.vvd' -o -iname '*.vtx' -o -iname '*.phy' -o -iname '*.ani' \
-o -iname '*.pcf' -o -iname '*.ttf' -o -iname '*.otf' \
-o -iname '*.wav' -o -iname '*.mp3' -o -iname '*.ogg' \
\) -print0 | while IFS= read -r -d '' file; do
mkdir -p "$NEW/$(dirname "$file")"
cp -- "$file" "$NEW/$file"
bzip2 -9 -k -f -- "$NEW/$file"
done
done
done
count=$(find "$NEW" -type f ! -name '*.bz2' | wc -l)
if [ "$count" -eq 0 ]; then
rm -rf "$NEW"
echo "No files to publish: current version kept." >&2
exit 1
fi
ln -sfn "$NEW" "$WEB/current"
# Delete the oldest releases
ls -1dt "$WEB"/releases/* | tail -n +$((KEEP + 1)) | xargs -r rm -rf --
echo "Publishing complete: $count files in $NEW"Make the script executable, then run it:
sudo -u gmod chmod 700 /home/gmod/fastdl-sync.sh
sudo -u gmod /home/gmod/fastdl-sync.shThe gamemodes/darkrp/content folder is skipped if it does not exist. It is listed because DarkRP marks some of its files with resource.AddFile: they must therefore also be available on FastDL. Add to SOURCES any other addon whose content is marked.
Step 5: Configure Nginx
sudo nano /etc/nginx/sites-available/gmod-fastdlserver {
listen 80;
listen [::]:80;
server_name fastdl.your-domain.com;
root /var/www/gmod-fastdl/current;
autoindex off;
gzip off;
types { }
default_type application/octet-stream;
add_header X-Content-Type-Options nosniff always;
access_log /var/log/nginx/gmod-fastdl.access.log;
error_log /var/log/nginx/gmod-fastdl.error.log;
location / {
return 404;
}
location ~ ^/(maps|materials|models|particles|resource|sound)/ {
limit_except GET {
deny all;
}
try_files $uri =404;
}
}Only the content folders are accessible. Enable the site, test the configuration and reload Nginx:
sudo ln -s /etc/nginx/sites-available/gmod-fastdl /etc/nginx/sites-enabled/gmod-fastdl
sudo nginx -t
sudo systemctl reload nginxnginx -t must report syntax is ok and test is successful.
Step 6: Open Port 80
Use the firewall tool already in place on your server.
With UFW
sudo ufw allow 80/tcp
sudo ufw reloadWith iptables
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4With nftables
sudo nft add rule inet filter input tcp dport 80 accept
(echo "flush ruleset"; sudo nft list ruleset) | sudo tee /etc/nftables.confStep 7: Check the Site
Test one of your files, adapting its path. The first command must answer 200:
curl -I http://fastdl.your-domain.com/materials/my_server/logo.vmt.bz2
curl -fsS http://fastdl.your-domain.com/materials/my_server/logo.vmt.bz2 | bunzip2 | sudo -u gmod cmp - /home/gmod/gmod-server/garrysmod/addons/my_content/materials/my_server/logo.vmtThe cmp command must display nothing: the published file is then identical to the original.
Also check that nothing else is accessible. These two requests must answer 404:
curl -I http://fastdl.your-domain.com/
curl -I http://fastdl.your-domain.com/cfg/server.cfgStep 8: Mark the Files for Download
Create a server-side Lua file:
sudo -u gmod mkdir -p /home/gmod/gmod-server/garrysmod/lua/autorun/server
sudo -u gmod nano /home/gmod/gmod-server/garrysmod/lua/autorun/server/fastdl.luaresource.AddFile( "materials/my_server/logo.vmt" )
resource.AddFile( "models/my_server/crate.mdl" )
resource.AddFile( "sound/my_server/announcement.mp3" )Give the path starting from garrysmod/, without addons/my_content/ and without .bz2. resource.AddFile also adds related files: the .vtf of a .vmt, or the .vvd, .vtx and .phy of a .mdl. The game limits this list to 8192 files.
Step 9: Enable FastDL on the Server
sudo -u gmod nano /home/gmod/gmod-server/garrysmod/cfg/server.cfgAdd these lines, with no trailing / on the address:
sv_downloadurl "http://fastdl.your-domain.com"
sv_allowdownload 0sv_allowdownload 0 disables direct download from the game server, which is slow and open to abuse. Restart the server:
sudo systemctl restart gmod.serviceStep 10: Check in Game
-
On the server, follow the requests:
Terminalsudo tail -f /var/log/nginx/gmod-fastdl.access.log -
On your computer, delete the test content from the
garrysmod/download/folder if it exists -
Connect to the server
Requests for your .bz2 files must appear with the 200 code, and the content must show up in game. Press Ctrl+C to stop following the log.
Updating Content
The game does not compare file contents: a player who already has a file does not download it again, even if it changed. To distribute a new version, give the file a new name and adapt fastdl.lua as well as the references to the file.
Then publish, and restart the server if fastdl.lua changed:
sudo -u gmod /home/gmod/fastdl-sync.sh
sudo systemctl restart gmod.serviceRolling Back
Go Back to a Previous Release
sudo -u gmod ls -1t /var/www/gmod-fastdl/releases
sudo -u gmod ln -sfn /var/www/gmod-fastdl/releases/YYYY-MM-DD_HH-MM-SS /var/www/gmod-fastdl/currentThe change is immediate, with no Nginx restart.
Disable FastDL
sudo systemctl stop gmod.service
sudo -u gmod cp -p /home/gmod/server.cfg.before-fastdl /home/gmod/gmod-server/garrysmod/cfg/server.cfg
sudo -u gmod rm -f /home/gmod/gmod-server/garrysmod/lua/autorun/server/fastdl.lua
sudo rm -f /etc/nginx/sites-enabled/gmod-fastdl
sudo nginx -t && sudo systemctl reload nginx
sudo systemctl start gmod.serviceThe copy of server.cfg does not include changes made after step 1: reapply them if needed.
Troubleshooting
HTTP ERROR 1 (Zero Length File) downloading ... or HTTP ERROR 2 (Connection closed) downloading ...
These messages appear in the player's console. Check that sv_downloadurl starts with http://, that the Cloudflare proxy is disabled on the subdomain and that the indicated file answers with curl -I.
The Nginx Log Shows 404 Errors
The file is not published, or its path differs. List the failing requests:
sudo awk '$9 == 404 {print $7}' /var/log/nginx/gmod-fastdl.access.log | sort | uniq -c | sort -rn | headCheck the case of the path, add its folder to SOURCES if needed and run the script again. Requests to / or other unrelated addresses often come from bots and can be ignored.
The Nginx Log Shows 403 Errors or Permission denied
Check each permission level:
sudo namei -l /var/www/gmod-fastdl/current/materialsThe folders must belong to the www-data group. If you published as a user other than gmod, fix the permissions, then run the script again:
sudo chown -R gmod:www-data /var/www/gmod-fastdlmkdir: cannot create directory ... Permission denied
The script was not run as gmod, or the folder was not created in step 2. Use sudo -u gmod /home/gmod/fastdl-sync.sh.
No files to publish
The source folder is empty, or the files are not in materials, models, sound or another recognized folder. Check the folder structure from step 3.
bind() to 0.0.0.0:80 failed (98: Address already in use)
Another service is using port 80. Identify it with sudo ss -ltnp | grep ':80 '.
Players Download Nothing
- Check the active value with
rcon sv_downloadurl - Check that the file is marked in
fastdl.luaand present on the game server: otherwise, it is not added to the list - The player may have limited downloads in their options. The
cl_downloadfiltercommand in their console must be set toall - The file may already be in their
garrysmod/download/folder
Players Still See the Old Version
This is normal game behavior. Rename the file, as described in the update section.
FAQ
Should I publish Workshop addons on FastDL?
No. Use resource.AddWorkshop, described in the server installation guide.
Can I host FastDL on another server?
Yes. Install Nginx on that machine and copy the contents of current there with rsync or scp. The files must remain on the game server, otherwise resource.AddFile does not add them to the list.
Are .bz2 files mandatory?
No, but they reduce the transferred volume. The script also keeps the normal version, used if the compressed version is missing.