1 year ago

#203116

test-img

Neil

Django in Docker on Nginx request to self fails when in the context of another request

I have a Django application deployed inside a container on top of Nginx using Dokku. One of the view functions of the Django application includes a request:

views.py

def foo(request):
...
response = requests.get(url)
...

It is probably noteworthy that url is the url of the Django application itself, so the request is from the application to itself. The request is to one of the API endpoints (the reasons for doing this are historical). When the view is called then the request to url fails with 504 gateway timeout.

I cannot reproduce this in any other context specifically:

  • There is no error when running on localhost with the development server, where url is then the url of the development app (localhost to itself works).
  • There is no error when running on localhost with the development server, where I manually make the url the production url (localhost to production works).
  • There is no error when running this request on the production server but outside of the view. Specifically, I did a docker exec into the container, started the Django environment (manage.py shell), and ran the exact request that the view was making, and it worked! (production to production works) It seems that only when the request is made in the context of a view which itself is answering another request I get an issue.

Any ideas?

django

docker

nginx

gunicorn

dokku

0 Answers

Your Answer

Accepted video resources