I have django
application and nginx
, from browser, it access to the file /static.
such as
http://example.com/static/file.png
However my application has files under /staticroot.
http://example.com/staticroot/file.png
it shows the image.
So, I set on nginx
.
location /static {
alias /staticroot;
}
However it doesn’t appear
My environment is Debug mode.
My settings py is like this,
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(config("PROJ_PATH"), 'staticroot')
How can I fix this?
2
Answers
In order to serve staticroot content you’ve to rename your
STATIC_URL='/staticroot/'
& in nginx file make changes like thisWhen request comes to
/staticroot/somefile
Nginx will look for directory named as staticroot in file system and it will serve provided file.So when you define url for your static or media content make sure you’ve created directory with the same name.
For more info check Serving Static Content on Nginx docs.
in
/etc/nginx/sites-available/you_project
set
in settings.py