James
James

Reputation: 865

Django + Gunicorn + SCRIPT_NAME

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:

Steps:

  1. 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)

  2. I can go to http://127.0.0.0:8000/demo. It loads the app home page as expected.

  3. The Page1 link shows as http://127.0.0.0:8000/demo/page1, I click and it takes me as expected to Page1

  4. 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

Answers (0)

Related Questions