Open In App

Django Web Application Deployment On AWS EC2 With Windows Server

Last Updated : 19 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 have knowledge about setting up EC2 in AWS. So let’s proceed with the article.

What is Django?

Django is a Python framework for developing and building web applications in Python. It supports rapid development and Scalability. It follows MVC architecture for developing web apps. You can read more about Django from this article Django.

Benefits of Deploying Django Application of EC2 With Windows Server

  • Amazon EC2 provides a simple and efficient option for the deployment of applications
  • It supports high scalability and throughput. It can be scaled up or down as per requirement.
  • Windows server supports GUI which helps in easy configuration of applications.

Steps to Deploy Django Application in AWS EC2 Windows Server

Create an AWS free tier account for that you can refer to the Amazon Web Services (AWS) – Free Tier Account Set up.

Step 1: First, we have to create an Amazon EC2 instance running Windows Server. Under launch instance on AWS give your instance a name and select Windows Server as OS. Specify other options as per your choice.

Launch-an-instance-_-EC2-Management-Console---Google-Chrome-10-08-2023-12_14_15-(3)

Step 2: Make sure you allow HTTP traffic to instance . You can also allow HTTPS if you want.

Configure the instance details

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 elastic ip address which is also fine . Connect to the instance using Remote Desktop Connection by downloading rdp file from aws console.

Connecting to the server
Step 4: Once you connect to instance download and install Python and other Django requirements according to your project . Also Download Nginx for windows . Unzip Nginx zip into C: drive of windows .After installing python add your project to instance or you can create new project. For the tutorial I have created simple django project that displays “Hello World” on home page route.Here is views.py file for project

GFG-Instance---ec2-3-85-221-32compute-1amazonawscom---Remote-Desktop-Connection-10-08-2023-14_37_17-(2)

  • Below is urls.py for project

GFG-Instance---ec2-3-85-221-32compute-1amazonawscom---Remote-Desktop-Connection-10-08-2023-14_38_47-(3)

  • Start the server to test the application . Note down address at which the server is started by default it is 127.0.0.1:8000

GFG-Instance---ec2-3-85-221-32compute-1amazonawscom---Remote-Desktop-Connection-10-08-2023-14_24_26-(2)

  • You should be able to access the page at 127.0.0.1:8000/home .

GFG-Instance---ec2-3-85-221-32compute-1amazonawscom---Remote-Desktop-Connection-10-08-2023-14_37_08-(2)

  • Once the app is tested we can deploy it . We will set up reverse proxy for app . To do so go to nginx folder in C: drive and open nginx.conf file from conf folder. Under http conf change server name to your instance public IP address and for ‘/’ location replace everything with proxy_pass forwarding to django local server . The file after changes should look like below .

GFG-Instance---ec2-54-161-186-127compute-1amazonawscom---Remote-Desktop-Connection-11-08-2023-12_41_56-(2)

  • Save the file and now open nginx.exe file from nginx folder this will start the server at public IP . Now go to browser and hit your instance public IP to access the application . (You should access /home route to view the “Hello world” message). If you see Hello World then you have successfully deployed your Django Application .

Troubleshooting Django Web Application

  • If you cant access the landing page make sure your Nginx server is allowed on firewall . If not add Nginx to the allowed apps in firewall.
  • If you get access denied error make sure HTTP access is enabled for EC2 instance.

FAQs on Django Web Application Deployment On AWS EC2

1. What Are Other Ways To Deploy Django Applications On AWS ?

You can deploy your web application in different ways by using different applications some them are you can use AWS Beanstalk, AWS lambda, AWS ECS and AWS EKS.

2. How To Add Load Balancer For EC2 Instance?

You need to follow some steps to attach the load balancer to the AWS EC2-Instance for that you can refer to the Elastic Load Balancer in AWS.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads