Tuesday, January 1, 2013

deploying static files and django applications with Nginx

Just learned a trick to serve static files as well as django applications with nginx. In the following setup, nginx tries to serve static files first, if the requested file is not found, then it passes request to the (django) application server (gunicorn, if you wish).


    location / {
        try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        proxy_pass   http://127.0.0.1:8080;
    }


If we want to enable user-dir mode, the configuration code should be put before these.

No comments:

Post a Comment