Logo services.quelltext.eu

One Server Many Services - Nginx Proxy Manager

Nginx Proxy Manager allows hosting several services on one web server.

Nov 28, 2024 - 3 minute read
feature image Nginx Proxy Manager

Nginx Proxy Manager runs in front of all the services on my machine. The image below shows a set of services that are running on the same machine.

image
Nginx Proxy Mangaer allows managing many domains and redirect services.

Getting a Server

Since I am hosting the services with Hetzner, I will have to add a domain configuration for the domain quelltext.eu that I bought.

image
The Hetzner server has an IPv4 and an IPv6 address.

Redirecting a Domain

I use selfhost.eu or thenames.co.uk to buy my domains. There are surely more services and they all work the same.

The table below shows the IP address configuration for the place where I bought the domain.

DomainRecord TypeValue
*.hosted.quelltext.euA78.47.87.181
*.hosted.quelltext.euAAAA2a01:4f8:c012:e355::1

After this is setup, it can take an hour for the information to propagate. Then, all domains like these redirect to the one server.

Setting up the proxy manager

I installed Docker and Docker Compose on the server. I also recommend:

  • git to version control your service changes
  • mosh to login on mobile
  • disable ssh password access and use public key authentication instead

Then, I created this docker-compose file.

mkdir services
cd services
git init
nano docker-compose.yml

This

# docker-compose.yml
services:
  nginx-proxy-manager:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81' # This is the initial port for admin setup. Remove later.
      - '443:443'
    volumes:
      - ./nginx-proxy-manager/data:/data
      - ./nginx-proxy-manager/letsencrypt:/etc/letsencrypt
    networks:
      - default

Now, you can start the service with this command:

nicco@ubuntu-4gb-fsn1-1:~/services$ docker compose up -d
[+] Running 1/0
 ✔ Container services-nginx-proxy-manager-1    Running      0.0s 

Firewall Configuration

Usually, a firewall blocks access to what is going on. Ports 80 and 443 must be let through to the service. The image below shows the firewall config.

image
Ports 443 and 80 must be configured in the firewall.

After the firewall config, your service should be running under your domain. In my case, I can visit hosted.quelltext.eu and see this:

image
Nginx Proxy Manager is running successfully.

Now, you can use ssh port forwarding to configure the user account at port 81.

Automatic Updates

I also have an update.sh file running in cron job in the same directory as the docker-compose.yml.

#!/bin/bash
#
# update the services
#

cd "`dirname \"$0\"`"

docker compose pull
docker compose create
docker compose up -d --remove-orphans
  
# clean up
# see https://stackoverflow.com/a/46159681/1320237
docker system prune -a -f
docker rm -v $(docker ps -a -q -f status=exited)
docker rmi -f  $(docker images -f "dangling=true" -q)
docker volume ls -qf dangling=true | xargs -r docker volume rm

More services

By now, we can add a simple service, Uptime Kuma. That is the next blog post.