Why does Django on App platform give a 400 response to Health Check but is fine otherwise?

As the title says, deploys great with Health Check set to TCP, whole service works fine. But if Health Check is set to HTTP on / then gunicorn core.wsgi:application gives 400.

My guess is it’s an ALLOWED_HOSTS issue. In the environment variables, it’s set to,localhost,<domain of app> which works when deployed. But if Health Check is hitting a different domain, my guess is this won’t work?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@timjdavey the only way I’ve found to get around this is to set ALLOWED_HOSTS = [‘*’]. Of course, this now means you are responsible for validating the host header.

Update, doing it with DEBUG=True I get django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: ''. i.e. it’s hitting it from the IP of that dynamic instance. How do you get access to this IP so it can be added to the allowed hosts? gunicorn is running on so should allow internal IPs. I’ve tried most of the standard environmental variables but no joy.

I’m not keen on relying on TCP as a health check. If this doesn’t work I’m moving back to render which seems to work magically out of the box for everything.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel