1

I'm developing a small web GIS app with Django just for demo purposes.

Everything works fine with static and media files when debug=True, but when I set debug to False in production and want to serve static and media files through the web server (apache), using wsgi, I get 404 when sending a request to fetch the .tiff files from media folder (but files are there, I've checked the paths a million times).

I know it's not a good idea to serve .tiff files from media folder and from the same server Django uses, I know I should dedicate a different server for media and static files or use AWS S3 buckets (which is a plan for the future), but this is only a demo/presentation/PoC kind of an app and I want to know what am I doing wrong.

A working scheme is pretty straightforward, I process some images (geotiffs), store them locally in data folder (which is defined as a media folder in my project), save the path in PostgreSQL database and render it in frontend.

Like I said, everything works fine in production when debug=True, but when I change it to False for security reasons, only media files aren't working properly (static files are working just fine). Entire application is hosted on Amazon EC2 instance, Ubuntu 18.04, (added to allowed hosts) and I've granted all permissions on the data (media) folder with

sudo chmod -R 777 /var/DirectoryName (pretty desperate attempt I know... or maybe?).

Here is my wsgi configuration.

Media root/url definition:

MEDIA_ROOT  = os.path.join(BASE_DIR, 'data')
MEDIA_URL = '/data/'

added to the urls:

urlpatterns = [
    ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

and example of a path in postgres:

data/User_test_user33/Parcel_133_2020-11-03/20201103T095159_Parcel_133_2020-11-03/indices/aoi_ndvi_20201103T095159_Parcel_133_2020-11-03_4326.tif

I've read similar Q&A's but those solutions didn't help me (or maybe I'm missing something?). I could really use some help because I'm running out of answers. If you need any more details I'll gladly provide. If it's something obvious and I missed it, don't be harsh :)

markwalker_
  • 12,078
  • 7
  • 62
  • 99
trideset3
  • 85
  • 8

0 Answers0