-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Caddy server support and configuration (#13)
* feat: add Caddy server support and configuration - Create a Caddyfile to serve static and media files and to forward requests to Django - Update README.md with instructions for using Caddy as an alternative to Traefik - Add docker-compose.caddy.yml for easy setup with Caddy, Django, and Postgres * Update README.md
- Loading branch information
Showing
7 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{$MY_DOMAIN} { | ||
|
||
handle_path /static/* { | ||
root * /usr/share/caddy/static | ||
file_server | ||
} | ||
|
||
handle_path /media/* { | ||
root * /usr/share/caddy/media | ||
file_server | ||
} | ||
|
||
handle { | ||
reverse_proxy django:{$GUNICORN_PORT} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
version: "3.9" | ||
services: | ||
postgres: | ||
image: postgres:15 | ||
env_file: .env | ||
restart: unless-stopped | ||
volumes: | ||
- "postgres-data:/var/lib/postgresql/data/" | ||
|
||
django: | ||
build: . | ||
image: django-docker | ||
env_file: .env | ||
environment: | ||
- "DJANGO_ALLOWED_HOSTS=${MY_DOMAIN}" | ||
- "DJANGO_CSRF_TRUSTED_ORIGINS=https://${MY_DOMAIN}" | ||
- "DJANGO_SESSION_COOKIE_SECURE=true" | ||
- "DJANGO_CSRF_COOKIE_SECURE=true" | ||
- "DJANGO_SECURE_SSL_REDIRECT=true" | ||
restart: unless-stopped | ||
volumes: | ||
- "staticfiles-data:/var/www/static" | ||
- "media-data:/var/www/media" | ||
depends_on: | ||
- postgres | ||
|
||
caddy: | ||
image: caddy:2.7-alpine | ||
env_file: .env | ||
environment: | ||
- "MY_DOMAIN=${MY_DOMAIN}" | ||
restart: unless-stopped | ||
ports: | ||
- "80:80" | ||
- "443:443" | ||
volumes: | ||
- "./Caddyfile:/etc/caddy/Caddyfile:ro" | ||
- "caddy-data:/data" | ||
- "caddy-config:/config" | ||
- type: volume | ||
source: media-data | ||
target: /usr/share/caddy/media | ||
read_only: true | ||
volume: | ||
nocopy: true | ||
- type: volume | ||
source: staticfiles-data | ||
target: /usr/share/caddy/static | ||
read_only: true | ||
volume: | ||
nocopy: true | ||
|
||
volumes: | ||
caddy-data: | ||
caddy-config: | ||
media-data: | ||
postgres-data: | ||
staticfiles-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters