Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Django application in AWS. Raise Disallowed Host exception

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?

like image 442
Casimiro Rocha Avatar asked Apr 11 '17 14:04

Casimiro Rocha


2 Answers

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', ...]
like image 164
rrmerugu Avatar answered Nov 09 '22 03:11

rrmerugu


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/

like image 27
oshaiken Avatar answered Nov 09 '22 05:11

oshaiken