【问题标题】:Using a static Index page with Django and Nginx在 Django 和 Nginx 中使用静态索引页面
【发布时间】:2010-11-14 14:20:49
【问题描述】:

我正在使用 Django + Apache 和 Nginx 构建一个网站来提供我的静态内容。我的网站索引不需要任何后端 Django 编码,所以我需要在 nginx.conf 中进行哪些更改才能将 location / { } 的请求发送到我的静态内容中的某个 index.html,同时仍然允许我的 urls.py 处理适当的模式?

upstream backend {
   server 127.0.0.1:8080;
}

server {
   listen       192.168.1.20:80;
   server_name  www.example.com example.com;

   access_log   /home/userxyz/public_html/example.com/logs/nginx_access.log;
   error_log    /home/userxyz/public_html/example.com/logs/nginx_error.log;

   location / 
   {
      proxy_pass   http://127.0.0.1:8080;
      include      /etc/nginx/proxy.conf;
   }

   location ~ ^/(system|images|robots\.txt|css|js|favicon\.ico).*$
   {
      root    /home/userxyz/public_html/example.com/static-content/;
   }

   location /media/ 
   {
      root    /home/userxyz/public_html/example.com/;
   }
}

【问题讨论】:

    标签: django nginx django-urls


    【解决方案1】:
    location = / {
      root    /home/userxyz/public_html/example.com/static-content/;
    }
    

    【讨论】:

      【解决方案2】:

      类似的东西呢:

      location ~ ^/$
      {
          root /PATH/TO/index.html;
      }
      

      这个想法是给 nginx 一个完全匹配 '/' 的规则。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-24
        • 2010-11-10
        • 1970-01-01
        • 2018-06-17
        • 2019-06-25
        • 1970-01-01
        • 2013-03-07
        • 2019-06-20
        相关资源
        最近更新 更多