2π
In Nginx virtual server conf file inside server section you need to add to location sections for Nginx can serve files in /static/ and /media/ folders:
location /media {
alias /path/to/your/folder/media;
}
location /static {
alias /path/to/your/folder/static;
}
After that test Nginx configuration:
sudo nginx -t
and reload Nginx:
sudo nginx -s reload
(or restart β sudo /etc/init.d/nginx restart
)
0π
try this config using server root and try_files
upstream app_server {
server unix:/home/pi/door_site/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name 192.168.1.81;
client_max_body_size 4G;
access_log /home/pi/door_site/logs/nginx-access.log;
error_log /home/pi/door_site/logs/nginx-error.log;
root /path/to/root # place your static directories in root i.e /path/to/root/static
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
This will try to find your static file and then move onto your app server.
Make sure nginx is running as the right user to access your files and that your static files permissions are correctly set perhaps with:
chmod -R u=rwX,g=rwX,o=rX static_dir
π€bob
- [Answered ]-Django doesn't show image with debug True
- [Answered ]-Sending mail via smtp in Django
- [Answered ]-Django settings.py not updating
0π
I my case it was a permission issue on static directory and it worked after assigning proper permissions.
π€user4981459
- [Answered ]-Django count guest user when visiting of index page
- [Answered ]-Django1.8 and Mongoengine NameError: name 'IntegerField' is not defined
- [Answered ]-Django codemirror get code from editor
- [Answered ]-Error from installing Django using pip on mac
- [Answered ]-Django: Having arbitrary file access models
Source:stackexchange.com