How to run Django on a subpath

23. June 2019 AWS 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 were still pointing it to the / url instead of /backend/

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

My Django project was running with gunicorn on the url http://127.0.0.1:8180/

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

SSLProxyEngine on
ProxyPreserveHost On
<location backend="">
###########proxy settings###
ProxyPass http://127.0.0.1:8180/
ProxyPassReverse http://127.0.0.1:8180/
RequestHeader set "Host" "www.nixjango.com"
RequestHeader set X-SCRIPT-NAME '/backend/'
ProxyErrorOverride Off
</location>

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 settings.py on the Django Code.

So, simply add these lines to your settings.py

Hello

[[code]]czoxMDpcImVjaG8gaGVsbG9cIjt7WyYqJl19[[/code]]


Leave a Reply

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