django : Serving static files through nginx

后端 未结 5 1804
醉话见心
醉话见心 2020-12-04 09:40

I\'m using apache+mod_wsgi for django.
And all css/js/images are served through nginx.
For some odd reason, when others/friends/colleagues try accessing

5条回答
  •  [愿得一人]
    2020-12-04 10:30

    I also struggled with this. However, following trick worked for me:

    server {   
         listen   8000;   
         server_name  localhost;
    
         access_log  /var/log/nginx/aa8000.access.log;    
         error_log  /var/log/nginx/aa8000.error.log;    
    
           location / {   
               index  index.html index.htm;    
           }    
    
         location ^/static/ {    
            autoindex on;    
            root   /opt/aa/webroot/;    
         }    
     } 
    

    I just marked static as a regex with ^ and nginx started serving static files. No modification on Django side was needed.

提交回复
热议问题