Skip to content

Instantly share code, notes, and snippets.

@dryan
Last active September 7, 2023 11:04
Show Gist options
  • Select an option

  • Save dryan/8271687 to your computer and use it in GitHub Desktop.

Select an option

Save dryan/8271687 to your computer and use it in GitHub Desktop.

Revisions

  1. dryan revised this gist Jan 5, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion settings.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
    ALLOWED_HOSTS = [
    'yourdomain.tld',
    '.compute-1.amazonaws.com',
    '.compute-1.amazonaws.com', # allows viewing of instances directly
    ]

    import requests
  2. dryan created this gist Jan 5, 2014.
    16 changes: 16 additions & 0 deletions settings.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # Hosts/domain names that are valid for this site; required if DEBUG is False
    # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
    ALLOWED_HOSTS = [
    'yourdomain.tld',
    '.compute-1.amazonaws.com',
    ]

    import requests
    EC2_PRIVATE_IP = None
    try:
    EC2_PRIVATE_IP = requests.get('http://169.254.169.254/latest/meta-data/local-ipv4', timeout = 0.01).text
    except requests.exceptions.RequestException:
    pass

    if EC2_PRIVATE_IP:
    ALLOWED_HOSTS.append(EC2_PRIVATE_IP)