开发者

Nginx , SImple configuration for serving all the files in a Directory and all the directories within

开发者 https://www.devze.com 2023-04-12 07:13 出处:网络
I am looking for a simple configuration to serve all files and directories inside a particular folder.

I am looking for a simple configuration to serve all files and directories inside a particular folder.

To be more precise I am trying to serve everything inside the pinax /static_media/ folder and /media/ folder as it is with the same url, and preferably auto index everything .

by the way I have run python manage.py build_media --all so all static content is under <project_name>开发者_Go百科/site_media/static

The current configuration I am using :

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/;
    }

All the different configuration instructions from various sites has really confused me , for example

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

Environment information:

  • Xubuntu 10.04 running on VirtualBox
  • nginx 1.1.4
  • pinax 0.72
  • django 1.0.4
  • fastcgi for running django via nginx


I found the answer , It was Quite simple as i guessed . One has to set the root directory once and use the sub-directories as the location

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;
    }
}

I got a clue from

Nginx doesn't serve static

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号