Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SUPERUSER_USERNAME=root
SUPERUSER_PASSWORD=root
SUPERUSER_EMAIL=root@localhost
APP_PORT=8000
# TODO Replace 'app' below with the name of the django service in compose file
WEB_APP_HOST=app:8000
CSRF_TRUSTED_ORIGINS=http://localhost:$APP_PORT
ALLOWED_HOSTS=*

Expand Down
34 changes: 29 additions & 5 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,41 @@ services:
# condition: service_healthy

web:
image: mattcen/nginx_django
build: ./nginx
environment:
# Replace 'app' below with the name of the django service above
WEB_APP_HOST: app:8000
image: ghcr.io/nginx/nginx-unprivileged:alpine
configs:
- source: nginx_conf
target: /etc/nginx/conf.d/default.conf
ports:
- "$APP_PORT:80"
depends_on:
- app
volumes:
- media_files:/media
healthcheck:
test: '[ "$(curl -L -o /dev/null -s -w "%{http_code}\n" http://localhost/.nginx_healthcheck)" = 200 ]'
interval: 10s
timeout: 5s
retries: 5

configs:
nginx_conf:
#file: ./nginx.conf
content: |
upstream webapp { server ${WEB_APP_HOST}; }
server {
listen 80;
location / {
proxy_pass http://webapp;
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
proxy_set_header Host $$host;
proxy_redirect off;
}
location /media/ { alias /media/; }
location /.nginx_healthcheck {
return 200 'running';
default_type application/text;
}
}

volumes:
db_data:
Expand Down
34 changes: 29 additions & 5 deletions docker-compose.traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ services:
- backend

web:
image: mattcen/nginx_django
build: ./nginx
environment:
# Replace 'app' below with the name of the django service above
WEB_APP_HOST: app:8000
image: ghcr.io/nginx/nginx-unprivileged:alpine
configs:
- source: nginx_conf
target: /etc/nginx/conf.d/default.conf
depends_on:
- app
volumes:
- media_files:/media
healthcheck:
test: '[ "$(curl -L -o /dev/null -s -w "%{http_code}\n" http://localhost/.nginx_healthcheck)" = 200 ]'
interval: 10s
timeout: 5s
retries: 5
networks:
- backend
- proxy
Expand All @@ -59,6 +63,26 @@ services:
traefik.http.services.replace_this_name_with_something_else.loadbalancer.server.port: 80
traefik.http.services.replace_this_name_with_something_else.loadbalancer.sticky: "true"

configs:
nginx_conf:
#file: ./nginx.conf
content: |
upstream webapp { server ${WEB_APP_HOST}; }
server {
listen 80;
location / {
proxy_pass http://webapp;
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
proxy_set_header Host $$host;
proxy_redirect off;
}
location /media/ { alias /media/; }
location /.nginx_healthcheck {
return 200 'running';
default_type application/text;
}
}

volumes:
db_data:
media_files:
Expand Down
6 changes: 0 additions & 6 deletions nginx/Dockerfile

This file was deleted.

23 changes: 0 additions & 23 deletions nginx/default.conf

This file was deleted.

6 changes: 0 additions & 6 deletions nginx/docker-entrypoint-99-set-app-host.sh

This file was deleted.

Loading