Nginx: Multiple Django Projects with project root?
Question
Usually i'm using cherokee. Due to some critical issues with the latest chrome release i had to change my productive server to nginx for the time being.
Currently trying to get my configuration working as it did in cherokee. I'm using a very simple uwsgi handler:
location /project1 {
include uwsgi_params;
uwsgi_pass localhost:3032;
}
Works fine, the project is available on myurl.com/project1. But django takes myurl.com as project root.
Example how i want it to work: Multiple projects on one subdomain: project1 on /project1, project2 on /project2, etc.
The Django regex rule "^$" should work on every project like:
In Project1: ^$ -> /project1
In Project2: ^$ -> /project2 etc.
Is there a way to get this in nginx working?
Cheers,
Solution
nginx does not set SCRIPT_NAME automatically as Cherokee.
You can force it with
uwsgi_param SCRIPT_NAME /project1;
you then need to rewrite the PATH_INFO, uWSGI can do this automatically for you setting
uwsgi_modifier1 30
So full nginx config:
location /project1 {
include uwsgi_params;
uwsgi_param SCRIPT_NAME /project1;
uwsgi_modifier1 30;
uwsgi_pass localhost:3032;
}
Another approach would be doing the whole job in uWSGI passing --manage-script-name as option and leaving the nginx config untouched.