Skip to content

Commit

Permalink
Add a location block in the Nginx configuration file to directly serv…
Browse files Browse the repository at this point in the history
…e media files, add a volume mount for 'forum_media' to the Nginx container, delete redundant collectstatic command from CI/CD django_cd_dev
  • Loading branch information
YanZhylavy committed Sep 9, 2024
1 parent dfea4b1 commit aaf5d33
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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
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

0 comments on commit aaf5d33

Please sign in to comment.