Serving Django media from a volume
Hi, I'm trying to deploy a django app that needs to serve small size media from an attached volume. I've made this work by adding "[re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})]" to the url patterns in django, but this feels suboptimal.
The simplest thing (I've found googling) is to put nginx infront of gunicorn/django and have it direct /media to the volume path (and supposedly nginx handling all the incoming traffic first has other benefits).
Is there a way to do this using one service in django? Or do I deploy nginx as one service and django as another?
If two services, can the nginx service access the volume with media attached to django (or the other way around)? I've found templates for various parts of this setup but nothing that shows how to put it all together. Thanks!
The simplest thing (I've found googling) is to put nginx infront of gunicorn/django and have it direct /media to the volume path (and supposedly nginx handling all the incoming traffic first has other benefits).
Is there a way to do this using one service in django? Or do I deploy nginx as one service and django as another?
If two services, can the nginx service access the volume with media attached to django (or the other way around)? I've found templates for various parts of this setup but nothing that shows how to put it all together. Thanks!
Solution:Jump to solution
so my recommendation would be to continue using the method you have in your urls.py as it will be more than sufficient for hobby projects, and then when your app grows and you become more knowledgeable you can then tackle setting up a file server like caddy Infront of your django app
5 Replies
Project ID:
5bcf11b0-2e3b-4e09-8ca6-5f10085d0b1c
5bcf11b0-2e3b-4e09-8ca6-5f10085d0b1c
Just a quick follow up - thinking maybe this got lost over the weekend
not lost, but there's not really a super easy way to explain it without basically creating a template of what you're asking for, and I just haven't had the time
Solution
so my recommendation would be to continue using the method you have in your urls.py as it will be more than sufficient for hobby projects, and then when your app grows and you become more knowledgeable you can then tackle setting up a file server like caddy Infront of your django app
Makes sense, thanks!