相关疑难解决方法(0)

django:通过nginx提供静态文件

我正在为django使用apache + mod_wsgi.
并且所有css/js /图像都通过nginx.
出于某种奇怪的原因,当其他人/朋友/同事尝试访问该网站时,jquery/css没有为他们加载,因此页面看起来混乱了.

我的html文件使用这样的代码 -

<link rel="stylesheet" type="text/css" href="http://x.x.x.x:8000/css/custom.css"/>
<script type="text/javascript" src="http://1x.x.x.x:8000/js/custom.js"></script>
Run Code Online (Sandbox Code Playgroud)

我的nginx配置sites-available是这样的 -

    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/;    
         }    
     }   
Run Code Online (Sandbox Code Playgroud)

有一个目录/opt/aa/webroot/static/已相应cssjs目录.

奇怪的是,当我访问它们时页面显示正常.
我已经清除了我的缓存/等,但是从各种浏览器中我可以正常加载页面.

另外,我没有在nginx日志文件中看到404任何错误.

任何指针都会很棒.

django nginx

37
推荐指数
4
解决办法
7万
查看次数

标签 统计

django ×1

nginx ×1