拥有AWS S3(例如App.com)托管的网站
托管在Elastic Beanstalk(例如API.com)的API服务器
api
的URL如何禁用Django的无效http_host错误? Apache上的django无效的http_host标头 - 使用require?
Invalid HTTP_HOST header
settings.py
from socket import gethostname, gethostbyname # For AWS Healthchecker
HOST_NAME = gethostname()
HOST_IP = gethostbyname(HOST_NAME)
ALLOWED_HOSTS [
...
HOME_NAME, HOME_IP,
...
]
def get_ec2_private_ip(instance_name):
command = f"""aws ec2 describe-instances --filters "Name=tag:Name,Values={instance_name}" --query "Reservations[*].Instances[*].PrivateIpAddress" --output json"""
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout
地,您可以尝试以下操作:
https://pypi.org/project/django-allow-cidr/,但它允许整个范围,因此感觉不那么安全。
如果由于任何原因不安全,都会感谢任何反馈。