-
Notifications
You must be signed in to change notification settings - Fork 0
ScratchPad
You can use a single, centralized nginx-proxy container to manage your applications. This container will act as a reverse proxy and route traffic based on the subdomain to the correct application.
From the root directory of your VPS create a folder called shared proxy.
mkdir shared-proxyEnter the directory
cd shared-proxyMake a file called docker-compose.yml
touch docker-compose.ymlEnter file with VIM or NANO and enter contents.
vi docker.compose.ymlEnter contents
services:
nginx-proxy:
container_name: nginx-proxy
image: nginxproxy/nginx-proxy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx/html:/usr/share/nginx/html
- ./nginx/certs:/etc/nginx/certs
- ./nginx/vhost:/etc/nginx/vhost.d
- ./nginx/acme:/etc/acme.sh
networks:
- proxy-network
letsencrypt-companion:
container_name: letsencrypt-companion
image: jrcs/letsencrypt-nginx-proxy-companion
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:z
- ./nginx/acme:/etc/acme.sh:rw
networks:
- proxy-network
environment:
DEFAULT_EMAIL: <yourEmail>
networks:
proxy-network:
external: trueCreate the proxy-network Docker network by running this bash command (only once):
docker network create proxy-networkThis is an example of how you may set up your vite project locally. Here we are setting up this app: https://github.com/monatemedia/svelte-counter
From the root directory of your VPS create a folder called svelte-counter
mkdir svelte-counterEnter the directory
cd svelte-counterMake a file called docker-compose.yml
touch docker-compose.ymlEnter file with VIM or NANO and enter contents.
services:
svelte-counter:
container_name: svelte-counter
image: ghcr.io/monatemedia/svelte-counter:latest
environment:
VIRTUAL_HOST: monatehub.monatemedia.com
LETSENCRYPT_HOST: monatehub.monatemedia.com
networks:
- proxy-network
networks:
proxy-network:
external: trueSave and close the the file
This is an example of how you may set up your python django project locally. Here we are setting up this app: https://github.com/monatemedia/python-django-achievementhq
From the root directory of your VPS create a folder called python-django-achievementhq
mkdir python-django-achievementhqEnter the directory
cd python-django-achievementhqMake a file called docker-compose.yml
touch docker-compose.ymlEnter file with VIM or NANO and enter contents.
services:
achievementhq_db:
image: postgres:latest
restart: unless-stopped
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- proxy-network
achievementhq_web:
image: ghcr.io/monatemedia/python-django-achievementhq:latest
restart: unless-stopped
env_file:
- .env
environment:
VIRTUAL_HOST: achievementhq.monatemedia.com
LETSENCRYPT_HOST: achievementhq.monatemedia.com
networks:
- proxy-network
volumes:
postgres_data:
networks:
proxy-network:
external: trueSave and close the file
Start the centralized nginx-proxy setup:
cd ~
cd shared-proxy
docker compose upStart Each Application
cd /svelte-counter
docker compose up -d
cd /python-django-achievementhq
docker compose up -dFor more examples, please refer to the Documentation
You can make management of your various application scripts easier by creating scripts.
Navigate to your home directory
cd ~Create a new shell script, start-all.sh
touch start-all.shOpen the shell script
vi start-all.shAdd the following lines to the start-all.sh file. Replace the paths with the actual paths to your docker-compose.yml files:
#!/bin/bash
echo "Starting centralized proxy..."
cd /shared-proxy
docker compose up -d
echo "Starting svelte-counter app..."
cd /svelte-counter
docker compose up -d
echo "Starting python-django-achievementhq app..."
cd /python-django-achievementhq
docker compose up -d
echo "All services started!"
Save and close the VIM editor
Make the script executable by running:
chmod +x start-all.sh
Run the script
start-all.sh
Navigate to your home directory
cd ~Create a new shell script, stop-all.sh
touch stop-all.shOpen the shell script
vi stop-all.shAdd the following lines to the start-all.sh file. Replace the paths with the actual paths to your docker-compose.yml files:
#!/bin/bash
echo "Stopping python-django-achievementhq app..."
cd /python-django-achievementhq
docker compose down
echo "Stopping svelte-counter app..."
cd /svelte-counter
docker compose down
echo "Stopping centralized proxy..."
cd /shared-proxy
docker compose down
echo "All services stopped!"
Save and close the VIM editor
Make the script executable by running:
chmod +x stop-all.sh
Run the script
stop-all.sh
Navigate to your home directory
cd ~Create a new shell script, reboot-all.sh
touch reboot-all.shOpen the shell script
vi reboot-all.shAdd the following lines to the start-all.sh file. Replace the paths with the actual paths to your docker-compose.yml files:
#!/bin/bash
# Navigate to each project directory and restart the services
cd /path/to/svelte-counter
docker compose down && docker compose up -d
cd /path/to/python-django-achievementhq
docker compose down && docker compose up -d
# Add more directories as needed following the same pattern
echo "All services have been restarted successfully."
Save and close the VIM editor
Make the script executable by running:
chmod +x reboot-all.sh
Run the script
reboot-all.sh
If you want this script to run automatically when the server reboots:
edit your crontab
crontab -e
Add the following line to run the script at startup:
@reboot reboot-all.sh