Disallowed Host Error On Django AWS EC2 python by komal swami - November 7, 2023November 7, 20230 Django (Name of Guitarist) is one of the famous web framework follows MVT(Model View Template) architecture. Means you get most of the things required to develop client server application. In this article we have explained in short how to solve disallowed Host Error On Django AWS EC2. Lets see, How to fix disallowed host Django. We have developed application on local system and we need to test and deploy a Django application on AWS EC2 instance. For this we have created virtual environment on AWS, installed python. With this we get pip(python package installer like npm – node package manager in java). pip is used to get packages in this virtual environment. $pip install django create new Django project $django-admin startproject SEMApp This will create SEMApp folder with ‘manage.py’ and ‘SEMApp’ folder. In this ‘SEMApp’ folder ‘settings.py’ contains project related settings like AWS server name or IP address. ‘urls.py’ this will contain all the urls (uniform resource locators) definitions. ‘manage.py’ is file to manage all other activities henceforth, like to start the server. SEMApp$python manage.py runserver 0.0.0.0:8080 This will start the development server, then go to your favorite browser and enter AWS IP address along with port number, in my case it will be ‘52.66.179.3:8080’, this should give Django default index page with following message. This works flawless on local server but on AWS we were getting Disallowed host error, lets see how to solve it. Contents Disallowed host error in Django First check to do is, change ‘setting.py’ file from main project dir and add your AWS url or domain name to ‘ALLOWED_HOSTS’ Next step is to allow 8080 port to accept client connections. (venv)$ sudo ufw allow 8080 Lets configure using AWS console. How to add a security rule to run one application on port no 8080 in aws console To add a security rule to allow an application to run on port 8080 in the AWS console, you can configure the security group associated with your EC2 instance. Log in to the AWS Management Console: Go to the AWS Management Console -> Navigate to the EC2 Dashboard->Click on the “Services” menu and select “EC2” under the “Compute” section. In the EC2 dashboard ->Edit Security Group -> Scroll down to the “Description” tab and look for the “Security groups” section. You should see the security group associated with your instance. Click on the security group’s name to edit it. -> Add Inbound Rule: In the “Inbound rules” tab, you can add a new rule to allow incoming traffic on port 8080. Click the “Edit inbound rules” button. Add Rule for Port 8080: Click the “Add Rule” button to create a new rule. Configure the following settings: Type: Choose “HTTP” if you want to allow HTTP traffic. You can also choose “Custom TCP” if the application doesn’t use HTTP.Protocol: Select “TCP.”Port Range: Specify “8080” for the port you want to allow traffic on.Source: You can set the source IP range to “0.0.0.0/0” to allow traffic from any IP address. However, it’s more secure to limit the source to specific IP addresses or ranges if possible.Review and Save: Review the rule configuration, and then click the “Save rules” button to apply the changes. After adding the inbound rule to the security group, your application running on port 8080 should be accessible. Make sure that your application is also configured to listen on port 8080 within the EC2 instance. Now in browser enter your ‘domain name:8080’ or ‘EC2 IP Address:8080’ and Disallowed Host Error On Django AWS EC2 is solved. Share this:Click to share on Twitter (Opens in new window)Click to share on Facebook (Opens in new window)MoreClick to share on LinkedIn (Opens in new window)Click to share on WhatsApp (Opens in new window)Click to email a link to a friend (Opens in new window)Like this:Like Loading... Related