# Django gunicorn nginx EC2 - media files

**URL:** <https://forum.djangoproject.com/t/django-gunicorn-nginx-ec2-media-files/34245>\
**Category:** Deployment\
**Created:** [August 27, 2024, 10:42pm UTC](https://forum.djangoproject.com/t/django-gunicorn-nginx-ec2-media-files/34245 "2024-08-27T22:42:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CybSec113](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cybsec113/32/23529_2.png) [@CybSec113](https://forum.djangoproject.com/u/CybSec113)\
**Post date:** [August 27, 2024, 10:42pm UTC](https://forum.djangoproject.com/t/django-gunicorn-nginx-ec2-media-files/34245/1 "2024-08-27T22:42:34Z")

</div>

Hi,

I have researched Django treatment of media files (vs. static files). Most of the material on the subject assumes the media files are uploaded by the user. What if I have a small collection of images that I want to render - Would I still use MEDIA\_ROOT and MEDIA\_URL locations to store these files? (Currently, my web app does not contain any stored data.)

If my media files are stored in MEDIA\_URL, my understanding is also that these files are NOT included in `collectstatic` for deployment. So, in prod, are they served from the same directory as in dev? Did I get that right?

Finally, in dev and prod, all my static and media files are visible, but the media files (some small jpg images) are only partially loading (firefox) with the following error: `NS_ERROR_NET_PARTIAL_TRANSFER`. There is one image that is triggering the following message, but fully loads: `NS_BINDING_ABORTED`.

Help/feedback/guidance appreciated!

Josh

```auto
if os.environ.get("DEBUG", "True") == "True":
    # DEBUG=True
    STATIC_ROOT = os.path.join(BASE_DIR,'App/static')
    STATIC_URL = "App/static/"
else:
    # DEBUG=False
    STATIC_ROOT = os.path.join(BASE_DIR,'static-prod')
    STATIC_URL = "static-prod/"

MEDIA_ROOT = os.path.join(BASE_DIR, 'App/media')
MEDIA_URL = "App/media/"

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 27, 2024, 11:38pm UTC](https://forum.djangoproject.com/t/django-gunicorn-nginx-ec2-media-files/34245/2 "2024-08-27T23:38:14Z")

</div>

> [@CybSec113](#):
>
> Would I still use MEDIA\_ROOT and MEDIA\_URL locations to store these files?

That depends. Are these always going to be the same files? Or are these files you may be inclined to change, depending upon which installation you have, or some other criteria?

Rather than describing media files as “files uploaded by the user”, think of them as “files supplied after deployment.”

Note: _You_ are also a user - you might be the admin of the site, and so there may be files you want to change post-deployment, without needing to redeploy the site.

If they are files being deployed with your system, then they would be static files and not media files. (For example, a logo for your site might be a static file, if all deployments are going to use the same logo. However, it you’re going to have multiple deployments with different logo files, you might want to make that a media file.)

> [@CybSec113](#):
>
> If my media files are stored in MEDIA\_URL, my understanding is also that these files are NOT included in `collectstatic` for deployment.

That is correct.

> [@CybSec113](#):
>
> So, in prod, are they served from the same directory as in dev?

That is not correct. Again, the idea of these media files are that they’re supplied post-deployment. Because they are files being written by Django, you do _not_ want them being written anywhere within your project directory structure. In what I would consider a “production-quality” deployment, your MEDIA\_DIR is a directory set aside for specifically this purpose.

Also keep in mind that in a production-quality deployment, Django would _not_ be serving _either_ media files or static files. That’s something that your webserver would be doing. (See [Serving Media files from nginx](https://forum.djangoproject.com/t/serving-media-files-from-nginx/30922) as one of the topics on here talking about deployments of media and static files.)

Regarding the media file issues, I’d suspect some type of file corruption with how the files are being copied, but that’s pure conjecture.

---

<div class="post-metadata">

**Author:** ![CybSec113](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cybsec113/32/23529_2.png) [@CybSec113](https://forum.djangoproject.com/u/CybSec113)\
**Post date:** [August 27, 2024, 11:59pm UTC](https://forum.djangoproject.com/t/django-gunicorn-nginx-ec2-media-files/34245/3 "2024-08-27T23:59:26Z")

</div>

Very good. Thank you for clarifying! I feel like my images should be treated like true MEDIA files and will adjust accordingly. Yes, I understand that nginx is serving the files in my deployment… When I mentioned prod vs. dev, I meant `gunicorn`+`nginx` vs. `runserver`+`nginx`, respectively.

I built an amateur (first-time) web app and deployed on a t2-micro instance of EC2, just so I can learn development and deployment. For the time being, a directory outside my project tree would be somewhere like my home dir…

Expanding a bit on your reply, if I wanted to serve a Word doc, for example, for downloading, would it most likely sit in a media directory?

Thanks, again,  
Josh
