Please show me how I deploy a custom configured NGinX server with nix packages in Dokploy

Please show me how I deploy a custom configured NGinX server with nix packages in Dokploy
26 Replies
Siumauricio
Siumauricio12mo ago
create a docker compose application, then select raw
version: '3.7'

services:
nginx:
image: nginx:latest
ports:
- "8081:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
networks:
- dokploy-network
whoami:
image: traefik/whoami
ports:
- "80"
networks:
- dokploy-network

networks:
dokploy-network:
external: true
version: '3.7'

services:
nginx:
image: nginx:latest
ports:
- "8081:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
networks:
- dokploy-network
whoami:
image: traefik/whoami
ports:
- "80"
networks:
- dokploy-network

networks:
dokploy-network:
external: true
go to advanced -> volumes -> create new content:
events {}

http {
server {
listen 80;
server_name localhost;

location / {
proxy_pass http://whoami:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
events {}

http {
server {
listen 80;
server_name localhost;

location / {
proxy_pass http://whoami:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
mount path: ./nginx.conf then go to the browser and do: server-ip:8081 and you will see this
Siumauricio
Siumauricio12mo ago
No description
wvanheemstra
wvanheemstraOP12mo ago
Thank you so much @Siumauricio ! It seems to work, although when browsing in the browser to this Docker compose service it says “404 page not found”
Siumauricio
Siumauricio12mo ago
what do you mean? how you are accessing to the nginx?
wvanheemstra
wvanheemstraOP12mo ago
It looks like the issue lies with Environment variables not being picked up. For example through the Dokploy user interface I have set an environment variable “ APP_PORT=8081”, whereas the log of my deployment states “… msg=“The ”APP_PORT” variable is not set. Defaulting to a blank string.” I am on Dokploy version 0.2.4
Siumauricio
Siumauricio12mo ago
hmm are you using the env variable inside the compose file?
wvanheemstra
wvanheemstraOP12mo ago
Yes, like so: labels: - “traefik.http.services.${HASH}.loadbalancer.server.port=${APP_PORT}”
Siumauricio
Siumauricio12mo ago
got it, and the hash are you using what is the value?
wvanheemstra
wvanheemstraOP12mo ago
For the hash I use a ‘unique’ name, in this case HASH=app
Siumauricio
Siumauricio12mo ago
could you try to use like this?
traefik.http.routers.${HASH}.rule=Host(`${APP_PORT}`)
traefik.http.routers.${HASH}.rule=Host(`${APP_PORT}`)
this is a example from pocketbase template
version: "3.7"
services:
pocketbase:
image: spectado/pocketbase:0.22.12
restart: unless-stopped
ports:
- ${POCKETBASE_PORT}
networks:
- dokploy-network
labels:
- traefik.enable=true
- traefik.http.routers.${HASH}.rule=Host(`${POCKETBASE_HOST}`)
- traefik.http.services.${HASH}.loadbalancer.server.port=${POCKETBASE_PORT}
volumes:
- /etc/dokploy/templates/${HASH}/data:/pb_data
- /etc/dokploy/templates/${HASH}/public:/pb_public
- /etc/dokploy/templates/${HASH}/migrations:/pb_migrations

networks:
dokploy-network:
external: true
version: "3.7"
services:
pocketbase:
image: spectado/pocketbase:0.22.12
restart: unless-stopped
ports:
- ${POCKETBASE_PORT}
networks:
- dokploy-network
labels:
- traefik.enable=true
- traefik.http.routers.${HASH}.rule=Host(`${POCKETBASE_HOST}`)
- traefik.http.services.${HASH}.loadbalancer.server.port=${POCKETBASE_PORT}
volumes:
- /etc/dokploy/templates/${HASH}/data:/pb_data
- /etc/dokploy/templates/${HASH}/public:/pb_public
- /etc/dokploy/templates/${HASH}/migrations:/pb_migrations

networks:
dokploy-network:
external: true
enviroment variables: POCKETBASE_HOST=testing-pocketbase-fabbe4-179-49-119-201.traefik.me POCKETBASE_PORT=80 HASH=testing-pocketbase-5cbe9a
wvanheemstra
wvanheemstraOP12mo ago
Host(‘${APP_HOST}’) with backticks
Siumauricio
Siumauricio12mo ago
yeah
wvanheemstra
wvanheemstraOP12mo ago
Can it pick up the Environment variables set through the web user interface of Dokploy?
Siumauricio
Siumauricio12mo ago
What do you mean? dokploy will automatically inject the environment variables into your docker compose file. so you don't have to do anything
wvanheemstra
wvanheemstraOP12mo ago
Where do you store these environment variables? In Dokploy environments tab, or in a .env file in a GitHub repository?
Siumauricio
Siumauricio12mo ago
dokploy enviroments tab
Siumauricio
Siumauricio12mo ago
take a look about pocketbase template
No description
No description
wvanheemstra
wvanheemstraOP12mo ago
OK, then I don’t understand why the log says it is not set?
Siumauricio
Siumauricio12mo ago
try to reload traefik
wvanheemstra
wvanheemstraOP12mo ago
Please tell me how to reload traefik, thank you!
Siumauricio
Siumauricio12mo ago
Settings -> scroll down traefik -> reload
wvanheemstra
wvanheemstraOP12mo ago
Thanks, it says error to reload traefik
Siumauricio
Siumauricio12mo ago
Check logs
wvanheemstra
wvanheemstraOP11mo ago
I don’t see errors in logs Would a clean help? Thank you @Siumauricio your answer is fantastic and detailed! All works well, but when I try to check from a browser with server IP and port 8081 I get a warning “This site can’t be reached” instead of what you posted here. What is your advice, please.
Siumauricio
Siumauricio11mo ago
@wvanheemstra can you please show the docker compose file?
wvanheemstra
wvanheemstraOP11mo ago
services: nginx: image: nginx:latest ports: - "${APP_PORT}:80" volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro networks: - dokploy-network labels: - "traefik.enable=true" - "traefik.http.routers.${HASH}.rule=Host(${APP_HOST})" - "traefik.http.routers.${HASH}.entrypoints=websecure" - "traefik.http.routers.${HASH}.tls.certResolver=letsencrypt" - "traefik.http.services.${HASH}.loadbalancer.server.port=${APP_PORT}" whoami: image: traefik/whoami ports: - "80" networks: - dokploy-network networks: dokploy-network: external: true

Did you find this page helpful?