5

I am newbie in Amazon Web Services and I'm trying to deploy a Django application using elastic BeansTalk. I'm following the AWS developer guide and when I deploy the application using EBCLI and open the browser to see my application running, I get the following error.

Request Method: GET Request URL: http://django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com/

Django Version: 1.9.12 Python Version: 3.4.3 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "/opt/python/run/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response 123. response = middleware_method(request)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/middleware/common.py" in process_request 56. host = request.get_host()

File "/opt/python/run/venv/lib/python3.4/site-packages/django/http/request.py" in get_host 109. raise DisallowedHost(msg)

Exception Type: DisallowedHost at / Exception Value: Invalid HTTP_HOST header: 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com'. You may need to add 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com' to ALLOWED_HOSTS.

Obviosly the application was deployed but for some reason the exception raises.

Can anybody help me, please?

1

2 Answers 2

11

You are privileged to get such a verbose error..

Exception Type: DisallowedHost at / Exception Value: Invalid HTTP_HOST header: 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com'. You may need to add 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com' to ALLOWED_HOSTS.

Just add django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com to your ALLOWED_HOSTS in settings.py

Do something like this

#in settings.py

ALLOWED_HOSTS = [ 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com', ...]
Sign up to request clarification or add additional context in comments.

Comments

4

Try this:

ALLOWED_HOSTS = ['us-west-1.elasticbeanstalk.com']

in your settings.py file

Here is a great checklist before you deploy in prod. https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

1 Comment

adding ALLOWED_HOSTS = [*] is super insecure... It can mean that anyone who does a MIM attack with your code can legitimately run as you. I would NOT do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.