views:

710

answers:

2

I'm building a website using Django + Apache and Nginx to serve my static content. My site's index does not require any backend Django coding, so what would I need to change in nginx.conf to send requests for location / { } to some index.html in my static-content, while still allowing my urls.py to handle patterns appropriately?

upstream backend {
   server 127.0.0.1:8080;
}

server {
   listen       192.168.1.20:80;
   server_name  www.example.com example.com;

   access_log   /home/userxyz/public_html/example.com/logs/nginx_access.log;
   error_log    /home/userxyz/public_html/example.com/logs/nginx_error.log;

   location / 
   {
      proxy_pass   http://127.0.0.1:8080;
      include      /etc/nginx/proxy.conf;
   }

   location ~ ^/(system|images|robots\.txt|css|js|favicon\.ico).*$
   {
      root    /home/userxyz/public_html/example.com/static-content/;
   }

   location /media/ 
   {
      root    /home/userxyz/public_html/example.com/;
   }
}
A: 

What about something like

location ~ ^/$ { root /PATH/TO/index.html; }

the idea is to give nginx a rule for exactly matching '/'.

Jacob
A: 

I have an oposite problem. I'm able to make site root to be a static page, but i can't make django view to be default site page.

Nginx config could be found here, may help you (the idea is to use Nginx's "try_files" directive)

http://stackoverflow.com/questions/1376096/django-and-nginx-tryfiles-problem-for-site-root-page