Problem with Nginx+uwsgi deployment django unable to load static files

Nginx and uwsgi are installed, tested, no problem, and then when using uwsgi to start the django project, using the browser to view the project will have the problem that static files cannot be loaded. No matter how to configure it, I can"t do it well. I ask for advice from God.
nginx configuration, path is: / etc/nginx/conf.d/default.conf
server {

listen       80;
server_name  192.168.127.128;

charset UTF-8;
access_log      /var/log/nginx/SecondSpace_access.log;
error_log       /var/log/nginx/SecondSpace_error.log;

location / {
    include uwsgi_params;
    uwsgi_pass 192.168.127.128:8000;
    uwsgi_read_timeout 2;
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}
location /static {
    expires 30d;
    autoindex on;
    add_header Cache-Control private;
    alias /home/dh/PycharmProjects/python/SecondSpace/static;
 }
location /media {
    expires 30d;
    autoindex on;
    add_header Cache-Control private;
    alias /home/dh/PycharmProjects/python/SecondSpace/media;
 }

-sharperror_page  404              /404.html;

-sharp redirect server error pages to the static page /50x.html
-sharp
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

}
then comes the configuration of uwsgi.ini. The path is: / home/dh/PycharmProjects/python/SecondSpace/uwsgi.ini (my project directory when SecondSpace)
[uwsgi]
socket=:8000
chdir = / home/dh/PycharmProjects/python/SecondSpace
module = SecondSpace.wsgi
master=true
processes = 4
vacuum = true

ask the great god for advice. There is nothing I can do. I have finished reading the online tutorial. -sharp-sharp-sharp problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Mar.28,2021

clipboard.png
nginx accessing static files has nothing to do with uwsgi, it's the same configuration method. Both gunicorn and uwsgi are configured in this way.
this is how I write the screenshot, using root,
according to alias, you have to add / static/
to the path below to see if you can add the trailing / line.

there is also the question of whether nginx has access to your file directory. Take a look at who is the user running nginx


there should be no problem with looking at your configuration file. Please refer to the following points for troubleshooting:

  • 1. Check how static files are introduced in template.
  • 2. Check whether the requested static file address is correct in debug mode of the browser.

I hope it will be helpful to you.


first make sure that the DEBUG mode of django is turned off

secondly, make sure that there is a path to a static file in Nginx and point to the correct system directory

location /static/    <--  

finally, make sure that the relationship between uwsgi and Nginx is configured correctly.
since I wanted to take a note last time, I just remembered

.

look at the nginx log
access_log / var/log/nginx/SecondSpace_access.log;
error_log / var/log/nginx/SecondSpace_error.log;

and what is the url for accessing static files

Menu