I'm trying to serve static files with nginx for my Django app.
I'm following this guide in which they propose the following nginx config file:
server {
server_name yourdomainorip.com;
access_log off;
location /static/ {
alias /opt/myenv/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
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"';
}
}
And in my settings.py I have the following declarations:
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static/')
STATIC_URL = '/static/'
STATIC_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
I'm able to see the static files at urls of the form:
http://x.x.x.x/static/admin/img/icon_searchbox.png
However, when trying to reference static files in my templates using the {% static %} tag, I get urls of the form:
http://x.x.x.x:8001/static/admin/img/icon_searchbox.png
which doesn't point to the files and instead are procesed by Django.
Any ideas of how can I solve this?