Hosting Your Own Bit.ly Server Using Shlink on Linux

Key Notes

  • Install Docker to manage Shlink’s containers easily.
  • Set up an Nginx reverse proxy for SSL support.
  • Follow steps to create and test shortened links seamlessly.

A Complete Guide to Hosting Your Own Bitly Server with Shlink on Linux

Shlink is a robust self-hosting solution for link shortening that integrates seamlessly with your own branding while ensuring your data privacy. This guide will walk you through installing Shlink on Ubuntu Linux through the use of Docker and Nginx, providing you with a functional and secure link-shortening service.

Shlink’s standout advantage is its ability to use a custom domain for short links while maintaining a self-hosted setup. This grants the benefits of a cloud service combined with increased privacy since the software operates directly on your machine.

Additionally, Shlink offers various features like generating QR codes, forwarding links automatically, and creating customized slugs, making it a powerful tool for users looking for flexible link shorteners in a Linux environment.

How to Install Docker for Shlink

Assumption: This guide assumes you’re setting up Shlink on an Ubuntu 22.04 VPS with a registered domain name.

To begin deploying Shlink, you first need Docker. Start by fetching the signing key for Docker from their official repository:

Step 1: Install Docker

Create the file for Docker repository by executing the following command:

echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Then, update the system’s repository list with:

sudo apt update

Step 2: Install Dependencies for Shlink

With Docker ready, install necessary dependencies for Shlink by running:

sudo apt install docker-ce docker-ce-cli containerd.io

Ensure the “core” snap package is installed:

sudo snap install core

Install the “certbot” snap from the Electronic Frontier Foundation:

sudo snap install --classic certbot

Step 3: Obtain a Geolite2 License Key

Shlink’s unique feature includes tracking click locations. Head to the Geolite2 Licensing Sign Up page.

Complete the signup form and check your email for confirmation from MaxMind. Follow the link to set your password, then log in to manage your licenses.

Click Manage License Keys and generate a new key, then copy it for later use.

Step 1: Set Up a Docker Network

First, create a virtual Docker network. This helps containers communicate privately:

docker network create shlink_network

Next, deploy PostgreSQL and connect it to your new virtual network:

docker run --name shlink-postgres --network shlink_network -e POSTGRES_PASSWORD=yourpassword -d postgres

Change yourpassword to a secure password.

Run the following command to install Shlink:

docker run -d --name shlink --network shlink_network -e SHLINK_DB_DRIVER=pgsql -e SHLINK_DB_USER=postgres -e SHLINK_DB_PASSWORD=yourpassword -e SHLINK_DB_NAME=shlink -e SHLINK_DEFAULT_DOMAIN=yourdomain.com shlinkio/shlink

Make sure to replace all placeholders with your actual values.

Now, obtain your API key from the running container:

docker exec shlink-api shlink api:configure

Confirm everything is running correctly with:

docker ps

Setting Up an SSL Reverse Proxy with Nginx

With Shlink installed, the next step is to set up Nginx as a reverse proxy for SSL handling. Start by creating a new A record for your frontend.

Step 1: Create a DNS A Record

Set up your DNS records. Point the frontend A record to your server:

admin.yourdomain.com

Step 2: Configure Nginx

Open your Nginx configuration file and add:

server { listen 80; server_name admin.yourdomain.com; location / { proxy_pass http://shlink:8080; } }

Enable the site and reload the Nginx service:

sudo systemctl enable nginx && sudo systemctl restart nginx

To start using your Shlink instance, visit your frontend interface and select the Shlink menu.

Step 1: Create a Short URL

Input your long URL, provide metadata, and click Save to generate your short link.

Step 2: Test the Short URL

Open the newly created short URL in your browser and check its performance on the dashboard.

Additional Tips

  • Always verify your server’s settings after making changes.
  • Consider enhancing security with firewalls specific to your applications.
  • Regularly back up your Shlink database to prevent loss of data.

Summary

This guide presented steps to install and operate your Shlink instance on Ubuntu Linux, leveraging Docker and Nginx for optimal performance and security. Setting up an SSL proxy is critical for user privacy and establishing trust with your short links.

Conclusion

With Shlink, you can reclaim control over your link shortening needs while also enhancing your online privacy. Now that you have set up your own service, explore the versatile features Shlink offers, and customize it further to meet your individual requirements.

FAQ (Frequently Asked Questions)

What is Shlink?

Shlink is a self-hosted link shortener that allows users to create and manage short URLs using their custom domains while tracking link analytics.

Can I install Shlink on a non-Ubuntu Linux distribution?

Yes, Shlink can run on various Linux distributions as long as Docker is installed and configured properly.

Further Resources

For additional information on managing your server and enhancing online privacy, consider checking out the following resources:

Additional Tips

  • Always verify your server’s settings after making changes.
  • Consider enhancing security with firewalls specific to your applications.
  • Regularly back up your Shlink database to prevent loss of data.

Summary

This guide presented steps to install and operate your Shlink instance on Ubuntu Linux, leveraging Docker and Nginx for optimal performance and security. Setting up an SSL proxy is critical for user privacy and establishing trust with your short links.

Conclusion

With Shlink, you can reclaim control over your link shortening needs while also enhancing your online privacy. Now that you have set up your own service, explore the versatile features Shlink offers, and customize it further to meet your individual requirements.

FAQ (Frequently Asked Questions)

What is Shlink?

Shlink is a self-hosted link shortener that allows users to create and manage short URLs using their custom domains while tracking link analytics.

Can I install Shlink on a non-Ubuntu Linux distribution?

Yes, Shlink can run on various Linux distributions as long as Docker is installed and configured properly.