Serving a Django app on a sub-path

The default uWSGI configuration created by our Django application installer works for Django applications running at the root of your domain - that is, the Django app is attached to your site route using / as the URI path.

If you need to run your application on a URI path below the root (aka a sub-path) then some minor changes to your application's uWSGI configuration are needed.

The following steps show how to serve a Django app named myapp (owned by shelluser) on a URI path /foo:

1

If you've not done so already, edit your site to assign myapp to the URI path /foo.

2

Locate your application's uwsgi.ini file. By default this file is created in the root of your application directory like /home/username/apps/myapp/uwsgi.ini.

3

Open the uwsgi.ini file in your preferred editor.

4

Change the wsgi-file configuration line from this:

wsgi-file = /home/shelluser/apps/myapp/myproject/myproject/wsgi.py

... to this ...

mount = /foo=/home/shelluser/apps/myapp/myproject/myproject/wsgi.py

Be sure that the /foo in the mount line matches the URI path that you've assigned to the site in the control panel.

5

Add the following line to the end of the uwsgi.ini file:

manage-script-name = True
6

Save the file and exit your editor.

7

Restart the application:

/home/shelluser/apps/myapp/stop
/home/shelluser/apps/myapp/start

After you've restarted the application it should then be available on /foo or whatever URI path you assigned to it.

Finally, please note that with these instructions it is not necessary to use FORCE_SCRIPT_NAME in your Django project settings.