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_prefixscript_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/’.

About

Stéphane Raimbault

Développeur Open Source pour le Web et l’embarqué (Django, JS, libmodbus). http://webstack.fr

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store