I have a django app running with nginx and gunicor.
The images, CSS and JS files are not loading! When I was checking the error log file (/var/log/nginx/error.log) I could see the path the machine is considering is different than the one I’ve typed!!! One of the errors, but they are all the same:
[error] 25420#25420: *3487 open() "/home/ubuntu/petangel/staticfilesgeneral_template.css" failed (2: No such file or directory),
but the path is: /home/ubuntu/petangel/staticfiles/general_template.css
on the other hand in the /etc/nginx/sites-enabled/default:
location /static/ {
alias /home/ubuntu/petangel/staticfiles;
}
location /images/ {
alias /home/ubuntu/petangel/crud/media/media;
}
location = /favicon.ico {
alias /home/ubuntu/petangel/crud/static/iconscat.png;
}
Side note: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. This forces the forum software to keep your code properly formatted. (I’ve taken the liberty of modifying your original post for this.)
Unless I’m missing something here, you should be able to change this:
To this:
alias /home/ubuntu/petangel/staticfiles/;
(This should also be done for your /images/ alias.)
Side note 2: I never recommend granting permissions into a home directory to nginx. I always recommend that in a deployment environment that both static and media directories reside completely outside the directories in which the code itself is stored.
See my comment at Django and Nginx permission issue on Ubuntu - #2 by KenWhitesell for more information about this.
Hello Ken
Thank you so much for your help, the static files are working already!
But for images, in my project calls media, is there any additional info should I provide beyond these ones:
I meant: my images files are located in: /home/ubuntu/petangel/crud/media/media
also I do have these configs:
MEDIA_ROOT = os.path.join(BASE_DIR, 'crud/media/')```
and
```location /static/ {
alias /home/ubuntu/petangel/staticfiles/;
}
location /images/ {
alias /home/ubuntu/petangel/crud/media/media/;
}
location = /favicon.ico {
alias /home/ubuntu/petangel/crud/static/iconscat.png;
}```
but the images are not loading...
Then you need to show the details of the results. Show the log file from the server and the console log in the browser where it’s trying to retrieve those files, along with the change that you made to the nginx configuration file.