Steps to Deploy Django Application in AWS EC2 with Ubuntu Server
Step 1: First, we have to create an Amazon EC2 instance running any Linux distribution of your choice. Under launch instance on AWS give your instance a name and select Ubuntu Server as OS. Specify other options as per your choice.
Step 2: Make sure you allow HTTP traffic to the instance . You can also allow HTTPS if you want.
Step 3: After specifying all options correctly click launch instance. Once the instance is started successfully copy the public IP address assigned you will need it later. You may have assigned an elastic ip address which is also fine. Connect to the instance using PuTTY or OpenSSH.Once you connect to the instance download and install Python and other Django requirements according to your project. Ubuntu may have already installed Python. If it is not there install it using the below command.
sudo apt install python3
Step 4: Install nginx using the below command.
sudo apt install nginx
- After installing Python add your project to the instance or you can create a new project. For the tutorial, I have created a simple Django project that displays “Hello World” on the home page route.
- Here is the views.py file for the project
- Below is urls.py for the project
Step 6: Start the server to test the application. Note down the address at which the server is started by default it is 127.0.0.1:8000. You should be able to access the page at 127.0.0.1:8000/home.
How to Deploy Django Application in AWS EC2?
In this article, we will study how we can deploy our existing Django web application to Windows Server in AWS EC2. We will also see how to use the public IP of the EC2 instance to access the Django application. For this article, you should know about setting up EC2 in AWS. We will see how to deploy applications on Linux As Well as Windows OS.