Nginx not serving Static files
First of I would like to mention that I don’t have extensive knowledge of Linux and Nginx I am new to all this.
Now my problem…
I have a Django app(intranet) that I need to host internally within our network. The challenge is that the site loads expect for the static files(img, css and js).
I have changed the permissions on the static folder to add www-data since that’s the user Nginx is using.
I have added the needed config for the location /static/{}
The project root is on the desktop for “webadmin”, server is running Ubuntu.
All packages were installed via apt including Nginx. I have attached screenshots as well as the output for the error log for Nginx.
Simple chown will solve your problems, nginx user has no access to files and you’re getting permission denied
Change the 'alias' to 'root'
Can u help me with the same proble but nothing working i am gettin 404 not found even when i cd to that static path it works but web page says not found
The directive is root not alias. And the final path might contain static twice, so you might need to omit it in the root directive.
Looking in access.log might help to see this behavior.
The webserver must be allowed to read all the directories along the path.
when i check the access log this is what i get
webadmin@intranet:~$ sudo tail -F /var/log/nginx/access.log
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET / HTTP/1.1" 200 3418 "http://intranet.randwestcity.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/img/carousel-1.png HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/img/carousel-2.png HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/llib/easing/easing.min.js HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/img/call-to-action.gif HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/img/team-1.png HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/img/property-1.png HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/llib/waypoints/waypoints.min.js HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/llib/owlcarousel/owl.carousel.min.js HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
10.100.43.92 - - [08/Mar/2024:11:20:05 +0200] "GET /static/js/main.js HTTP/1.1" 403 134 "http://intranet.servername.gov.za/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"
i changed alias to root and tested nginx and restarted the service everything checks out.
But the error still persists.
server {
listen 80;
server_name servername;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /static/ {
root /home/webadmin/Desktop/intranet;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
If all the chown done trice doesnt work. Check selinux
You have mentioned an alias, but an alias to what?
You should replace alias with root, and also make certain nginx has permission to access the files.
In the folder with the static files type "sudo chown -R www-data:www-data *".
Should work for you.
I just love that a government employee of any country is posting their web server configuration on a public site.
the web server is not exposed to the internet.