# shlink
A [self-hosted](https://shlink.io/) URL shortener.

## Run docker instance

```
docker run \
    --name my_shlink \
    -p 8080:8080 \
    -e DEFAULT_DOMAIN=s.test \
    -e IS_HTTPS_ENABLED=true \
    -e GEOLITE_LICENSE_KEY=xyz123 \
    shlinkio/shlink:stable
```

* *--name* - can be whatever
* *DEFAULT_DOMAIN* - set to *yourdomain.com*
* *IS_HTTPS_ENABLED* - enable for HTTPS support (automatic via LetsEncrypt)
* *GEOLITE_LICENSE_KEY* - optional - read about it [here](https://shlink.io/documentation/geolite-license-key/).  You can exclude this setting if you don't want to geolocate where your link clicks are coming from.

## Enable HTTPS using Caddy
Use a `Caddyfile` such as:
```
yourdomain.com {
    reverse_proxy http://127.0.0.1:8080
}
```

Then run it:
```
./caddy run --config ./Caddyfile
```

## Generate an API key via docker
```
sudo docker exec -it my_shlink shlink api-key:generate
```

Write it down!

## Install Web client to interact with shlink
* Download from [here](https://github.com/shlinkio/shlink-web-client/releases/)
* Unzip the zip

## Run the Shlink Web portal to manage your instance
Using something like Caddy where `/home/www/` is where the shlink Web interface is unzipped:

```
sudo caddy file-server \
  --root /home/www \
  --listen :8888
```

## Enable HTTPS in the Web management portal
Per [this discussion on GitHub](https://github.com/orgs/shlinkio/discussions/200), you'll have problems copying links to clipboard in the browser if you're not in a secure context while doing so.  So once I get the Caddy file server going (see previous section) I setup another tmux session and run something like:

```
sudomain-I-setup-for-shlink-admin.mydomain.com {
    reverse_proxy http://127.0.0.1:8888
}
```

!!!tip
I highly recommend firewalling off port 8888 such that only your home/work IPs can access it, or put behind some sort of VPN
!!!

## Stop/restart the instance
You can press `Ctrl+C` to stop the instance, but next time you start it docker will complain that the container name is in use, so you can just do:
```
sudo docker start my_shlink
```

Stop it again:
```
sudo docker stop my_shlink
```

## Review shlink logs
Review the logs with:
```
sudo docker logs -f my_shlink
``` 
