Nginx, SImple configuration for serving all files in a directory and all directories inside

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

To be more precise, I try to serve everything in the pinax /static_media/ and /media/ /static_media/ , as it is with the same URL, and it is preferable to automatically index everything.

by the way, I ran python manage.py build_media --all , so all static content is under <project_name>/site_media/static

Current configuration I'm 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 various setup instructions from different sites really confused me, for example

How to serve all existing static files directly using NGINX, but the proxy server remains on the 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 runs on VirtualBox
  • nginx 1.1.4
  • pinax 0.72
  • django 1.0.4
  • fastcgi to run django through nginx
+4
source share
1 answer

I found the answer: β€œIt was pretty simple, as I guessed. You need to set the root directory once and use the subdirectories 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 have a key to

Nginx does not stat

+6
source

All Articles