Question
Nginx is not serving the static files that have been collected inside the project directory.
I have seen others face the same issue. Some were solved with user permission, some with a problem in configuration. However, I have double-checked the configuration and user profile and can’t figure out the root of this problem.
My project folder is at the root folder and not inside the home/user directory. Its user permission and the dir structure are as follows:
drwxr-xr-x 4 bsal_dev root 4096 Jan 17 11:44 eiapp
drwxr-xr-x 3 bsal_dev root 4096 Jan 17 14:20 enginfinity
-rwxr-xr-x 1 bsal_dev root 631 Jan 16 04:56 manage.py
drwxrwxr-x 9 bsal_dev bsal_dev 4096 Jan 17 12:05 static (STATIC_ROOT)
drwxr-xr-x 8 bsal_dev root 4096 Jan 16 04:56 statics(statics contents of the app)
drwxr-xr-x 3 bsal_dev root 4096 Jan 16 04:56 templates
drwxr-xr-x 2 bsal_dev root 4096 Jan 16 04:56 templatetags
drwxr-xr-x 4 bsal_dev root 4096 Jan 16 04:57 venv
My settings.py configuration:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'statics'),
]
MY NGINX CONFIG
/etc/nginx/sites-available/enginfinity
server {
server_name xxx.xxx.xx;
access_log off;
location /static/ {
alias /enginfinity/static
}
location / {
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×