Search code examples
djangonginxdotcloud

Nginx and Django on Dotcloud


I currently have a dotcloud app that uses django to serve everything. It works great, however, we recently had our site redone in angular.js, and I don't want to use django to serve the actual html pages (I want to just use nginx for that), but I want django to serve some links for the API we built for the angular code to use.

Is it possible for me, in the same app, to configure nginx to serve some static files for particular urls, and have it send other urls for django to serve?

I want nginx to serve my index.html page is a request comes in to wwww.example.com, but if a request for example.com/api/login/ comes in, I want that to be handled by django. Is this possible?


Solution

  • Yes, you can do what you are looking for, you just need to add an nginx.conf to your project and then specify which urls you want nginx to serve and which ones you want django to serve, by default they will all go to django, so you just need to specify which ones you want to be served by nginx.

    Here is an example for serving static files from nginx, you can use this as a guide to do what you need.

    location /media/ { 
          root /home/dotcloud/data ; 
    }
    location /static/ { 
          root /home/dotcloud/volatile ; 
    }