How to run Django On a subpath – DevOps

23. June 2019 DevOps 0

Today, we were trying to run the Django application on a subpath say /backend/ . We were able to run it but some URL redirection from the application was still pointing it to the / URL instead of /backend/

Let me share the configuration a high level, please comment if you need any clarification.

My Django project was running with gunicorn on the URL

Below is the configuration on my Apache, and yes the application should be on h

SSLProxyEngine on
ProxyPreserveHost On

###########proxy settings###
RequestHeader set "Host" ""
RequestHeader set X-SCRIPT-NAME '/backend/'
ProxyErrorOverride Off

With the above configuration the application will still forward any redirection from the /backend/ , ie say /backend/admin/ to /admin . So we need to add force /backend from the on the Django Code.

So, simply add these lines to your

FORCE_SCRIPT_NAME = '/backend'

Once the above lines are added, restart gunicorn and apache. Now, you will be able to access the /backend/ and /backend/admin/ URL redirection will just work fine.

Leave a Reply

Your email address will not be published. Required fields are marked *