pythondjangonginxarmbian

NGINX and Django not in debug serving some static files and some no


I am experiencing some weird behaviour after switching off DEBUG on Django, behind NGINX reverse proxy.

I am testing it on a Armbian Linux with Python 3.7.3.

Django project has the manage.py inside the folder

folder configuration is

- /var/webserver/backend
  - manage.py
  - backend
    - settings.py
  - static
    - img (contains collected plus my logo and favicon)
    - admin (the collected admin files)

The NGINX configuration is as following (the static part, the rest is a reverse proxy with a self signed certificate):

location /static {
      autoindex on;
      autoindex_exact_size off;
      alias /var/webserver/backend/static;
    }

The settings.py static part is as following, staticfiles app is in the APPS:

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'static'

I run the manage.py command while in the /var/webserver/backend directory, nginx is ran as service.

I think I have tried all combinations of "slashes" both inside the NGINX configuration and settings.py (before, after, both, none)

This configuration is the nearest to work, the situation is the following:

I kept cache disabled on the browser to avoid non-reloaded pages.

I really can't get what's not working.

I tried changing the configuration any way, I tried installing WhiteNoise and put it in the Apps with no success. I tried changing "alias" with "root" inside the NGINX configuration and it went worse (also images went down)

Thanks anyone who will help, let me know if something else is needed.


Solution

  • There might be a several reasons why it is happening.

    1. Make sure you include mime types in your nginx conf file.
    /etc/nginx/mime.types;
    location /static {
       ...
    }
    
    1. Some people report that Whitenoise's whitenoise.storage.CompressedManifestStaticFilesStorage storage backend doesn't work well in some cases. Try to change it to whitenoise.storage.CompressedStaticFilesStorage.