【问题标题】:Nginx , SImple configuration for serving all the files in a Directory and all the directories withinNginx ,用于提供目录中的所有文件以及其中的所有目录的简单配置
【发布时间】:2011-12-04 00:08:32
【问题描述】:

我正在寻找一种简单的配置来为特定文件夹中的所有文件和目录提供服务。

更准确地说,我正在尝试为 pinax /static_media/ 文件夹和 /media/ 文件夹中的所有内容提供相同的 url,并且最好自动索引所有内容。

顺便说一句,我运行了python manage.py build_media --all,所以所有静态内容都在<project_name>/site_media/static

我正在使用的当前配置:

server {
    listen   80;
    server_name  QuadraPaper;

    access_log  /home/gdev/Projects/QuardaPaper/access_log.log;

    location ^*/site_media/*$
    {
        autoindex on;
        access_log off;
        root /home/gdev/Projects/QuardaPaper/site_media;
    }

    location /media/ {
        autoindex on;
        root   /home/gdev/Projects/QuardaPaper/media/;
    }

来自不同站点的所有不同配置说明真的让我很困惑,例如

How to serve all existing static files directly with NGINX, but proxy the rest to a backend server.

http://coffeecode.net/archives/200-Using-nginx-to-serve-static-content-with-Evergreen.html

https://serverfault.com/q/46315/91723

http://wiki.nginx.org/Pitfalls

http://pinaxproject.com/docs/0.7/media/#ref-media-devel

环境信息:

  • Xubuntu 10.04 在 VirtualBox 上运行
  • nginx 1.1.4
  • pinax 0.72
  • django 1.0.4
  • 通过 nginx 运行 django 的 fastcgi

【问题讨论】:

    标签: django nginx pinax static-files


    【解决方案1】:

    我找到了答案,就像我猜的一样简单。 必须设置一次根目录并使用子目录作为位置

    server {
        listen   80;
        server_name  QuadraPaper;
    
        access_log  /home/gdev/Projects/QuardaPaper/access_log.log;
        root /home/gdev/Projects/QuardaPaper;
    
        location /site_media/ {
            autoindex on;
            access_log off;
        }
    
        location /media/ {
            autoindex on;
        }
    }
    

    我从

    那里得到了线索

    Nginx doesn't serve static

    【讨论】:

      猜你喜欢
      • 2017-09-13
      • 2015-09-28
      • 2014-03-08
      • 2017-03-15
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 2015-08-13
      • 2020-08-22
      相关资源
      最近更新 更多