大网数据广告活动
服务器运维问答

Django App Public IP Works but `400 Bad Request Error` when A Record Update

· 52CE 我爱测

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 er…

问题原文

原帖链接 · twk · CC BY-SA 3.0

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.

社区高分解答

原帖链接 · twk · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。