'I have django application and nginx
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?
Solution 1:[1]
In order to serve staticroot content you've to rename your STATIC_URL='/staticroot/' & in nginx file make changes like this
location /staticroot/ {
alias /home/your_username/project_name;
}
When 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.
Solution 2:[2]
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'),
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | oruchkin |
