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

1

5

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>/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
Improvised answered 9/10, 2011 at 15:19 Comment(0)
I
8

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

Improvised answered 9/10, 2011 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.