Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Nginx to serve Django media files #771

Merged
merged 2 commits into from
Sep 9, 2024
Merged
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: 0 additions & 2 deletions .github/workflows/django_cd_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ jobs:
run: docker compose -f docker-compose.dev.yml exec ${{ vars.API_DEV }} python manage.py loaddata categories
- name: Docker compose LOADDATA regions
run: docker compose -f docker-compose.dev.yml exec ${{ vars.API_DEV }} python manage.py loaddata regions
- name: Docker compose COLLECTSTATIC
run: docker compose -f docker-compose.dev.yml exec ${{ vars.API_DEV }} python manage.py collectstatic --no-input
- name: nginx
run: docker compose -f docker-compose.nginx.yml down -v
- name: nginx
Expand Down
9 changes: 5 additions & 4 deletions configs/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ server {
proxy_redirect off;
}

# Media files
location /media/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://api-dev:8000/media/;
proxy_redirect off;
alias /home/forum/app/public/media/;
access_log off;
expires 30d;
add_header Cache-Control 'public, no-transform';
}

# Django API
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ services:
redis:
image: redis:7
container_name: redis
ports:
- 6379:6379
networks:
- forum_network
networks:
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ services:
- 80:80
networks:
- forum_network
volumes:
- media:/home/forum/app/public/media

networks:
forum_network:

volumes:
media:
external:
name: forum_media
Loading