YOURLS Link Shortener with Docker
Set up YOURLS link shortener with Docker for a quick and simple way to manage your links.
Docker Compose
Create a folder named “yourls”:
mkdir yourls
cd yourls
Create docker-compose.yml:
nano docker-compose.yml
Edit compose.yml:
version: '3.1'
services:
yourls:
image: yourls
restart: always
ports:
- 10082:80
environment:
YOURLS_DB_PASS: ****
YOURLS_SITE: https://go.example.com
YOURLS_USER: juyoung
YOURLS_PASS: ****
volumes:
- ./plugins:/var/www/html/user/plugins
- ./root:/var/www/html
mysql:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ****
MYSQL_DATABASE: yourls
volumes:
- ./mysql-data:/var/lib/mysql
- Change
YOURLS_SITE
. - Use the same password for both
YOURLS_DB_PASS
andMYSQL_ROOT_PASSWORD
. - Set
YOURLS_USER
and use a unique password forYOURLS_PASS
. These will be your username and password for logging into YOURLS dashboard.
If your password has a $
symbol, write $$
instead. This is because Docker thinks $
is a variable name and $$
tells it to use a normal $
.
(Retrieved from YOURLS Docker Hub on January 23, 2025)
Caddy
Install Caddy:
apt install caddy
sudo systemctl enable caddy
Open Caddyfile:
nano /etc/caddy/Caddyfile
Edit Caddyfile:
example.com {
# You can use a different name instead of "/go." Change "YOURLS_SITE:" in docker-compose.yml file.
route /go* {
uri strip_prefix /go
redir https://go.{host}{uri}
}
}
# To use a different port, change the "ports:" section in your docker-compose.yml file.
go.example.com {
reverse_proxy localhost:10082
encode zstd gzip
}
Restart Caddy:
sudo systemctl restart caddy
Go to YOURLS dashboard at https://go.example.com/admin or at https://example.com/go/admin if you prefer using a subpath. Don’t forget the “/admin” part.
YOURLS Plugins
YOURLS comes with minimal features, but you may want to install plugins for additional functionality. You can find a list of available plugins at YOURLS Awesome Plugins (https://github.com/YOURLS/awesome).
To install a plugin, create a folder named after the plugin inside the “plugins” folder.
Run ls
to view the “plugins” folder and go into it:
ls
cd plugins
Create folder named after the plugin:
mkdir <plugin-name>
Place plugin files inside this folder, then go to Plugins administration page to activate the plugin.
Recommended Plugins
- 404 If Not Found: Shows a 404 error page if the short URL doesn’t exist.
- QRCode Local: Adds .qr at the end of the short URL to display a QR code.
- Every Click Counts: Counts multiple clicks by the same client.
- Fallback URL: Redirects if the short URL doesn’t exist.
- JSON Response: Adds .json at the end of the short URL to display info as a JSON response.
- Login Timeout: Protects login page against brute force attacks.
- Redirect Index: Redirects the user if they go to the base directory.
- Timezones