Reputation: 865
I have a number of django apps running off the same domain but am having problems getting SCRIPT_NAME to work properly with Gunicorn.
Example app paths:
Scenario1: I currently have each app running on Elastic Beanstalk and modify the apache config to deal with the SCRIPT_NAME side of things. This works.
Scenario2: I have been testing using AWS ECS/FARGATE and in that config I only have a container running Django/Gunicorn. There is no Apache/Nginx etc. I intend to just use Django/Gunicorn/Whitenoise/Cloudfront. This is not working. The SCRIPT_NAME value to make django work with sub paths is duplicating.
To simplify/troubleshoot I am running the code/commands below locally, so AWS is not involved. I have also created a bare bones/simple django app for testing.
My app page structure is like this:
<a href="{% url 'demo:page1' %}">Page1</a>
<a href="{% url 'demo:home' %}">Home</a>
<a href="{% url 'demo:page2' %}">Page2</a>
<a href="{% url 'demo:home' %}">Home</a>
Steps:
I launch the webserver:
gunicorn config.wsgi --env SCRIPT_NAME=demo -b 0.0.0.0:80 --keep-alive 20 --log-file=- --log-level debug --capture-output
(its running in a docker container)
I can go to http://127.0.0.0:8000/demo
. It loads the app home page as expected.
The Page1 link shows as http://127.0.0.0:8000/demo/page1
, I click and it takes me as expected to Page1
The Home link shows as http://127.0.0.0:8000/demo/demo/
. It has duplicated the SCRIPT_NAME and the link doesn't work.
Any ideas what I am doing wrong? Is this meant to work?
Upvotes: 4
Views: 4914