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?
CodePudding user response:
In order to serve staticroot content you've rename your STATIC_URL='/staticroot/'
& in nginx file
location /staticroot/ {
alias /home/your_username/project_name;
}
When request come 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 you static or media content make sure you've directory with same name.
For more info check Serving Static Content on Nginx docs.
CodePudding user response:
in /etc/nginx/sites-available/you_project
set
location /static/ {
root /home/your_admin_name/your_project_folder_name;
}
in settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]