系统相关
首页 > 系统相关> > django – Nginx,用于提供目录中所有文件的SImple配置以及其中的所有目录

django – Nginx,用于提供目录中所有文件的SImple配置以及其中的所有目录

作者:互联网

我正在寻找一个简单的配置来提供特定文件夹中的所有文件和目录.

更确切地说,我试图在pinax / static_media /文件夹和/ media /文件夹中提供所有内容,因为它使用相同的URL,并且最好自动索引所有内容.

顺便说一句,我运行python manage.py build_media – 所以所有静态内容都在< 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

环境信息:

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

解决方法:

我找到了答案,我觉得这很简单.
必须设置一次根目录并使用子目录作为位置

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

标签:nginx,django,static-files,pinax
来源: https://codeday.me/bug/20190613/1235611.html