Deploy your Django project as directory

This method of deployment is convenient if you have a non wildcard SSL certificate for your domain. This way, you can add another application to your domain in a new directory (eg. example.com/foo/).

The first step is to set up nginx to pass SCRIPT_NAME to your app:

location /foo/ {
include uwsgi_params;
uwsgi_param SCRIPT_NAME /foo;
uwsgi_modifier1 30;
uwsgi_pass unix:/run/uwsgi/app/foo/socket;
}

In your Django application, you must always use the URL resolver to generate URLs (reverse()), if you really want to hack your URLs you can use get_script_prefix() with something like that:

from django.core.urlresolvers import get_script_prefix
script_prefix = get_script_prefix()

The last step is to define STATIC_URL to ‘/foo/static/’ (and MEDIA_URL if used).

Note: admin URLs use the ‘admin’ namespace so for example, you can do resolve(‘admin:index’) to resolve as ‘/foo/admin/’.