title: how to serve media files in django app nginx server?
body: <p>I am testing my django app in production mode (debug=false) using nginx, gunicorn, postgresql.</p>
  
  <p>Though I am able to render static files, I am unable to access files stored in 'media' folder.</p>
  
  <p>In my settings.py following are the variables set:</p>
  
  <pre><code> MEDIA_URL = '/media/'
   MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
   # also tried another combination: MEDIA_ROOT = 'media'
  </code></pre>
  
  <p>Also in urls.py the MEDIA_ROOT settings are as follows:</p>
  
  <pre><code> urlpatterns = [
     path('admin/', admin.site.urls),
     path('venter/', include('appname.urls')),
   ]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  
  <p>And in my /etc/nginx/sites-available/ file I have the following settings:</p>
  
  <pre><code>server {
  listen 80;
  server_name website.com www.website.com ;
  
  location = /favicon.ico { access_log off; log_not_found off; }
  location /static {
      root /home/a/btawebsite;
  }
  
  location /media/ {
      root /home/a/btawebsite;
  }
  
  location / {
      include proxy_params;
      proxy_pass http://unix:/home/a/myproject.sock;
  }
  }
  </code></pre>
  
  <p>However while rendering the xlsx file stored in my django database as follows it throws me NOT found error.</p>
  
  <pre><code>{{file.output_file.url}}
  </code></pre>
  
  <p>I have tried every combination of configurations required for rendering MEDIA files but unable to achieve the outcome. 
  Thanks.</p>
  
  <p><strong>UPDATE: following changes to be made in settings.py</strong></p>
  
  <pre><code> MEDIA_URL = '/'
   MEDIA_ROOT = 'media'
  </code></pre>