How to Host Your Own bit.ly Server with Shlink in Linux
Shlink is a strong self-host attach shortener company for Linux. It lends a humble, yet undisputable framework in which you can serviceability your own domain name moniker as the root for your lowered affiliations. This blog post will affirm you how to arranged your own Shlink instance on Ubuntu Linux grossing serviceability of Docker and Nginx.
- Why Shorten Linkages grossing serviceability of Shlink?
- Amassing Docker for Shlink
- Amassing and Mounting Shlink
- Conceding an SSL Reverse Proxy grossing serviceability of Nginx
- Conceding Your First Web attach grossing serviceability of Shlink
Why Shorten Linkages grossing serviceability of Shlink?
One of the biggest commercializing and marketing junctures of Shlink is that you can serviceability your own tradition domain name for shortlinks while still being self-hostable. This, in rotate, confers you the adaptability of a SaaS attach shortener company as faultlessly as the confidentiality of running software on your own machine.

Aside from that, Shlink in improvement flaunts a multifaceted kit of services such as the capacity to invent QR codes, openly forward attach discomfiture, and invent multi-segment tradition slugs. This renders Shlink a handy gizmo if you’re sifting for a attach shortener company in Linux in which you can tweak how your affiliations sift and behave.
Nice to come to be aware: learn a number more about self-hosting by agreeing your own email pen names web server with SimpleLogin.
Amassing Docker for Shlink
Guess: This blog post infers that you’re placing Shlink on an Ubuntu 22.04 VPS and that you presently own a domain name moniker.
The initially activity in deploying Shlink on Linux is to acquire a photocopy of Docker. To do this, fetch the Docker project’s completing key from their portal:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg
Inflict the database record for your Docker binaries:
sudo nano /etc/apt/sources.list.d/docker.list
Paste the obeying straighten of code inside your favorite database record:
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable
Reload your gizmo’s database listing by implementing an apt update
:
sudo apt update && sudo apt upgrade
Mounting the Reliances for Shlink
Through the Docker databases up and running, you can presently serviceability proper to acquire the dependences for Shlink:
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-buildx-plugin nginx
Warranty that the “core” snap package is obtainable in your gizmo:
sudo snap install core
Bring and arranged the “certbot” snap package from the Digital Frontier Cornerstone:
sudo snap install certbot --classic
Amassing a Geolite2 Certificate Pivot
Another showing center of Shlink is that it can track the basic place of the visitor who clicked on your affiliations. To serviceability this, amenable the Geolite2 Licensing Indication Upwards page.

Fill in the form with your lays out, after that press Linger.
Responsive your email inbox, after that sift for the confirmation email from MaxMind.
Click the attach from the email, after that lend a password for your favorite MaxMind account.

Login to your MaxMind account, after that click Juggle Certificate Mysteries on your Control panel.

Click Collect favorite license key, after that click Confirm to invent your Geolite2 key.

Duplicate the Geolite2 license key to a message record on your machine after that conserve it.
Amassing and Mounting Shlink
To arranged Shlink, you should initially invent a virtual Docker network. This will serve as the app’s civilian network in which it can attach with the other cyndrical tubes that you will deploy:
sudo docker network create -d bridge --subnet=10.0.0.0/24 --gateway=10.0.0.1 shlink-network
Deploy a PostgreSQL database and attach it to your favorite virtual Docker network:
sudo docker run -d --name shlink-db -e POSTGRES_PASSWORD=!REPLACE_ME! -e POSTGRES_USER=postgres -e POSTGRES_DB=shlink -p 127.0.0.1:5432:5432 --restart always --network="shlink-network" postgres:12.1
Readjust the advantage of the “POSTGRES_PASSWORD” ensconcing variable with a random string of message.

Tab: You can invent this random string of message by grossing serviceability of “/dev/urandom”: cat /dev/urandom | tr -dc 'A-Za-z0-9' | fold -w 32 | head -n 1
Paste the obeying command to a favorite terminal session:
sudo docker run -d --name shlink-stable -p 8081:8080 -e DEFAULT_DOMAIN=YOUR-ROOT.DOMAIN -e IS_HTTPS_ENABLED=true -e GEOLITE_LICENSE_KEY=!REPLACE_ME! -e DB_DRIVER=postgres -e DB_USER=postgres -e DB_PASSWORD=!REPLACE_ME! -e DB_HOST=shlink-db --network="shlink-network" shlinkio/shlink:stable
Replace the advantage of the DEFAULT_DOMAIN variable with your domain name moniker.

Tab: Equip sure that your domain name has an A document that junctures to your machine’s IP address.
Readjust the advantage of the “GEOLITE_LICENSE_KEY” variable with your visitor license key.

Replace the “DB_PASSWORD” variable with your PostgreSQL database password.

Press Get in to prelude your Shlink instance.
Mounting and Attaching Your Shlink Consumer interface
Bring an API key from your Shlink canister, after that photocopy it to your clipboard:
sudo docker exec -it shlink-stable shlink api-key:generate
Paste the obeying command to a favorite terminal session:
sudo docker run -d --name shlink-client -p 8080:8080 -e SHLINK_SERVER_URL=https://YOUR-ROOT.DOMAIN -e SHLINK_SERVER_API_KEY=!REPLACE-ME! --network="shlink-network" shlinkio/shlink-web-client
Replace the “SHLINK_SERVER_URL” with the advantage from your “DEFAULT_DOMAIN” variable on the backend canister.

Paste your API key as the advantage for the “SHLINK_SERVER_API_KEY.”

Press Get in to prelude your Shlink frontend visitor interface.
Confirm that your database, Shlink backend, and Shlink frontend are kneading accordingly by listing with one voice the presently feisty cyndrical tubes in the gizmo:
sudo docker container list

Conceding an SSL Reverse Proxy grossing serviceability of Nginx
At this time you presently have a kneading Shlink software cheat running on your web server. In ordinance to access it, yet, you still should invent an SSL web proxy that entrusts your two cyndrical tubes on different domain names.
To prelude, invent a favorite A document for your Shlink’s frontend visitor interface. In my case, I will kit my frontend’s A document as “admin.”

Inflict the landmark config record for your Shlink instance grossing serviceability of your favored message editor:
sudo nano /etc/nginx/sites-available/shlink
Paste the obeying block of code inside your config record:
server { server_name YOUR-ROOT.DOMAIN; location / { proxy_pass http://127.0.0.1:8081; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; } } server { server_name SUBDOMAIN.YOUR-ROOT.DOMAIN; location / { proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; } }
Replace the “YOUR-ROOT.DOMAIN” variable with your root domain name, and the “SUBDOMAIN.YOUR-ROOT.DOMAIN” with the subdomain for your frontend visitor interface.
Preserve your config record, after that permit your web app in Nginx:
sudo ln -s /etc/nginx/sites-available/shlink /etc/nginx/sites-enabled/
Reload your Nginx daemon to use your favorite arrangements:
sudo systemctl reload nginx
Enroll your web server to the Digital Frontier Cornerstone:
sudo certbot register --agree-tos -m YOUR@EMAIL.ADDRESS
Execution a favorite multi-domain name SSL certificate for your Shlink instance:
sudo certbot --nginx -d YOUR-ROOT.DOMAIN -d SUBDOMAIN.YOUR-ROOT.DOMAIN
Confirm that your Shlink web server is kneading accordingly by reading to your instance’s admin console. In my case, it’s “https://admin.helloserver.apex.”

Nice to come to be aware: learn a number more about web security by agreeing your own SSL credentials grossing serviceability of OpenSSL.
Conceding Your First Web attach grossing serviceability of Shlink
To serviceability your favorite instance, click the Shlink menu thing on the landing page.

Paste your long URL on the URL to be lowered textbox under the Inflict a short URL group.
Equip some metadata for your short attach, after that click Preserve to invent your attach.

Responsive your favorite short URL on a favorite internet browser tab, after that click the Brows through switch on your Shlink dashboard to checkup if it’s kneading accordingly.

Mounting and deploying your own attach-lowering company is merely the initially activity in snagging previously your online confidentiality. Learn how Linux can help you better redeem your confidentiality by hosting your own confidential portal in Ubuntu grossing serviceability of Tor.
Image credit report: Carlos Muza wearing Unsplash and Shlink.io Developers. Unanimously improvements and screenshots by Ramces Red.