Deploying Shlink on a VPS: Enterprise-Grade Link Shortening with a Custom Domain
Introduction: The Case for Self-Hosted Link Shortening
In today's digital ecosystem, links serve as the primary bridges between businesses and their audiences. While third-party platforms like Bitly or Rebrandly offer quick solutions for link shortening, they come with substantial limitations for growing enterprises. High recurring subscription costs, restricted click analytics, and a lack of data ownership can hinder a brand's long-term digital strategy. Furthermore, relying on public domains for short links can dilute your brand authority and diminish user trust.
To overcome these challenges, forward-thinking organizations are turning to self-hosted alternatives. Shlink stands out as the premier open-source, enterprise-grade link shortener. By deploying Shlink on your own Virtual Private Server (VPS) and pairing it with a custom domain, you regain complete control over your data, access unrestricted analytics, and project a highly professional brand image. This comprehensive guide provides a step-by-step technical blueprint for deploying Shlink on a VPS, ensuring your business establishes a robust, secure, and scalable link-shortening infrastructure.
Why Choose Shlink Over Commercial Platforms?
Before diving into the technical deployment, it is essential to understand why Shlink represents a superior choice for business operations:
- Complete Data Privacy: All click data, visitor IP addresses, and tracking metrics are stored securely on your own server, ensuring compliance with strict data protection regulations such as GDPR.
- Cost Efficiency: Commercial platforms charge hefty premiums for custom domains and high click volumes. With Shlink, your only cost is your standard VPS hosting, regardless of how many links you generate or clicks you receive.
- Advanced Analytics: Shlink provides deep insights into visitor demographics, device types, referrers, and geolocations without restricting historical data availability.
- Multi-Domain Support: A single Shlink instance can manage multiple custom domains, making it perfect for agencies or conglomerates managing various brand portfolios.
- Robust API Integration: Shlink is built API-first, allowing seamless integration into your existing CRM, CMS, or automated marketing workflows.
Prerequisites for Deployment
To successfully execute this deployment, ensure you have the following prerequisites ready:
- A Virtual Private Server (VPS) running a clean installation of Ubuntu 24.04 LTS or Debian 12. A minimal configuration of 1 vCPU and 1GB RAM is sufficient for standard business traffic.
- A Custom Domain or subdomain (e.g.,
lnkd.yourbrand.com) dedicated exclusively to your shortened links. - SSH access to your server with a user possessing
sudoprivileges. - Basic familiarity with the Linux command-line interface.
Step 1: Domain and DNS Configuration
The foundation of a professional link shortener is its domain. Log in to your domain registrar's control panel (such as Cloudflare, Namecheap, or GoDaddy) and configure your DNS settings. You need to map your custom domain to your VPS IP address.
Create an A Record with the following details:
- Type: A
- Name:
@(for root domain) orlnkd(for a subdomain) - Value: Your VPS Public IP Address (e.g.,
192.0.2.1) - TTL: Automatic or 3600 seconds
Note: DNS propagation can take anywhere from a few minutes to several hours. Ensure this step is completed before proceeding to the SSL certificate installation.
Step 2: Server Preparation and Docker Installation
For ease of maintenance, scalability, and security, we will deploy Shlink using Docker and Docker Compose. Connect to your VPS via SSH and execute the following commands to update the system and install the required dependencies:
sudo apt update && sudo apt upgrade -y
sudo apt install curl git software-properties-common -yNext, install Docker and Docker Compose by executing the official installation script:
curl -fsSL [https://get.docker.com](https://get.docker.com) -o get-docker.sh
sudo sh get-docker.sh
sudo systemctl enable --now dockerVerify the installation by checking the versions:
docker --version && docker compose versionStep 3: Deploying Shlink via Docker Compose
We will use a secure docker-compose.yml file to orchestrate Shlink along with a production-ready MariaDB database instance. Create a dedicated directory for your deployment:
mkdir -p ~/shlink-deploy && cd ~/shlink-deploy
nano docker-compose.ymlPaste the following configuration into the file, replacing the placeholder values with your specific details:
version: '3.8'
services:
shlink-db:
image: mariadb:11
container_name: shlink-db
restart: always
environment:
MYSQL_ROOT_PASSWORD: YourVerySecureRootPassword
MYSQL_DATABASE: shlink
MYSQL_USER: shlink_user
MYSQL_PASSWORD: YourSecureDatabasePassword
volumes:
- shlink_db_data:/var/lib/mysql
shlink-web:
image: shlink/shlink:stable
container_name: shlink-web
restart: always
depends_on:
- shlink-db
ports:
- "8080:8080"
environment:
- DB_DRIVER=maria
- DB_USER=shlink_user
- DB_PASSWORD=YourSecureDatabasePassword
- DB_NAME=shlink
- DB_HOST=shlink-db
- DEFAULT_DOMAIN=lnkd.yourbrand.com
- IS_HTTPS_ENABLED=true
- GEOLOCATION_LICENSE_KEY=Your_MaxMind_GeoLite2_License_Key
volumes:
shlink_db_data:Save the file and exit the editor. Launch the containers in detached mode using the following command:
docker compose up -dStep 4: Setting Up Nginx Reverse Proxy and Let's Encrypt SSL
To securely expose Shlink to the public internet via HTTPS (port 443), we must configure Nginx as a reverse proxy and obtain a free SSL certificate from Let's Encrypt.
Install Nginx and Certbot:
sudo apt install nginx certbot python3-certbot-nginx -yCreate a new Nginx configuration file for your custom domain:
sudo nano /etc/nginx/sites-available/shlink.confAdd the following server block configuration:
server {
listen 80;
server_name lnkd.yourbrand.com;
location / {
proxy_pass [http://127.0.0.1:8080](http://127.0.0.1:8080);
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Enable the configuration by creating a symbolic link and restarting Nginx:
sudo ln -s /etc/nginx/sites-available/shlink.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxNow, secure your connection by requesting an SSL certificate:
sudo certbot --nginx -d lnkd.yourbrand.comFollow the on-screen prompts to complete the certificate generation and automatic redirection configuration.
Step 5: Managing Your Shlink Instance
Shlink is fully operational. To start generating short links, you need an API key. You can generate one directly from your terminal by executing a command inside the running Shlink container:
docker exec -it shlink-web shlink api-key:generateKeep this API key safe. To easily manage your links through a graphical interface, you can visit the official web client at app.shlink.io, enter your domain ([https://lnkd.yourbrand.com](https://lnkd.yourbrand.com)), and paste your API key. Rest assured, all management happens client-side in your browser; your data never passes through third-party servers.
Conclusion: Future-Proofing Your Digital Brand
Deploying Shlink on your own VPS represents a strategic upgrade for any data-driven business. It eliminates ongoing subscription bottlenecks, reinforces your brand's digital presence with a professional custom domain, and unlocks granular analytical insights that remain entirely under your control. By following this guide, you have successfully built a private, enterprise-ready infrastructure capable of supporting your marketing and operational goals for years to come.
