Django ALLOWED_HOSTS for Amazon ELB

前端 未结 2 2114
暖寄归人
暖寄归人 2021-02-20 07:03

I\'m using Django and I have the ALLOWED_HOSTS setting to include my EC2\'s private IP as per below:

import requests
EC2_PRIVATE_IP = N         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 07:57

    Fetching AWS internal IPs and adding to the ALLOWED_HOST is not the best solution. Since this Fetching will happen only on application reload. ELB IPs can change anytime.

    Instead of this, We can set actual host header in the nginx, if this the request is coming from an IP.

    Credit goes to: https://www.xormedia.com/django-allowed-hosts-and-amazon-elastic-load-balancer/

提交回复
热议问题