4

I've got a Django application deployed on an Ubuntu 16.04 EC2 instance using nginx and gunicorn.

Unfortunately, after a successful deployment with my public IP, updating my A record with the public IP yielded a 404 Bad Request error at my domain--even after waiting a long while to make sure DNS changes propagated. Accessing the application by the public IP continues to work. I did contact my name server host, to confirm if I correctly set my A record settings: they said the DNS change appeared successful, but could not help as it appeared it was an issue on AWS's side.

Is there a specific reason why utilizing my public IP in my A record is not working correctly and is not pointing to my application?

Thank you for anyone who might be able to help me get my domain to successfully point to my deployed django project. At present, the accessing the application via the public IP still works fine, the A record appears to be updated, but any attempts to load the domain (not the direct IP), renders a 400 Bad Request error.

3

I figured out a resolution. It does appear that using the public IP is acceptable, but I failed to add my domain name both to the ALLOWED_HOSTS file and to my nginx configuration.

Doing the following, I was able to get my domain to successfully point to my AWS EC2 deployment:

I did three things:

  • First, I updated my ALLOWED_HOSTS:
    • ALLOWED_HOSTS = ['12.345.67.890', 'sub.domain.com', 'www.sub.domain.com']
  • Then, I also edited the server_name setting in my nginx configuration:
    • server_name 12.345.67.890 sub.domain.com www.sub.domain.com;
  • Lastly, I restarted nginx and rebooted the machine to make sure it all worked:
    • sudo service nginx restart
    • sudo reboot

After this, my page loaded successfully.

2
  • 1
    Adding URl to ALLOWED_HOSTS did the trick for me. – Pratibha Jul 23 '18 at 2:42
  • +pratibha glad to see this helped you -- I had gotten stuck with this for awhile and it was an easy fix that took me some time to uncover! Best of luck to you! – twknab Jul 25 '18 at 6:58
0

I had the same issue, and solved by configuring a worker-class in Gunicorn. Also I had some trouble using gevent in python 3.7, better to use 3.6.

Django, Python 3.6 example:

Install:

pip install gevent

Run:

gunicorn --chdir myApp myApp.wsgi --workers 2 --worker-class=gevent --bind 0.0.0.0:80 --timeout=90 --graceful-timeout=10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.