Skip to main content

NGINX Web App Deployment for DevOps

 





  • Step 1: Create AWS instance.
  • Step 2: Install NGINX
  • Step 3: Install docker and create a Container for note-app.
  • Step 4: Set up a reverse proxy.
  • Step 5: Copy the code to the root folder.
  • Step 6: Connect the database
nginx specification



Step 1: Create AWS instance.
Log in to the AWS account and create an ec2 server.

Nginx is a web server that will serve you static web files. So we require a server.

- Create an EC2 instance and name it 'nginx-project-demo'. Also, don't forget to allow HTTP and HTTPS traffic.
( For sake of practice, let's select an Ubuntu machine with t2.micro instance type)

Update your server using the command.

 sudo apt-get update



Step 2: Install NGINX
Now install Nginx using the command below.

sudo apt install nginx


Check the status of nginx.
systemctl status nginx

Restart the nginx server with root user permission.

sudo systemctl restart nginx

To check further nginx is successfully installed on your server is to use the server IP and paste it into the browser URL. The below page will open. (default port will be 80 always)


Step 3: Install docker and create a Container for note-app.


Login to GitHub.

Copy the repository from the below GitHub link

https://github.com/Pranav0151/django-notes-app.git

Now clone this repository in the ubuntu server
git clone https://github.com/Pranav0151/django-notes-app.git


Build the app.

- To build the app we need Docker installed on the server.


sudo apt install docker.io

To set usermod permissions for docker use the command and reboot the server.


sudo usermod -aG docker $USER
sudo reboot



Switch to the 'django-notes-app' folder and build the app.


docker build -t notes-app .


Create a container

docker run -d -p 8000:8000 notes-app: latest


Now your application is running on port 8000. As a DevOps engineer, I don't want to expose my public IP on 8000. Instead, run it through the reverse proxy.






Step 4: Set up a reverse proxy.

On folder path '**/etc/nginx' all the Nginx installation and configuration files are present. In layman's language, all the engine parts are located here.



cd /etc/nginx
ls


Three files are important here and you must know.
'nginx.conf '- Nginx file containing settings that control its behavior and how it handles incoming requests.
'sites-available' - Directory in the Nginx web server that contains configuration files for individual websites or virtual hosts.
'sites-enabled' - This directory has symbolic links to active sites' configuration files in the sites-available directory and gets deployed...

Switch to the 'sites-enabled' folder and edit the 'default' file.


cd sites-enabled/
ls
vim default

Under 'location' write the command to pass a proxy as shown.

proxy_pass http://127.0.0.1:8000;


Now restart the Nginx server for changes to take effect.


sudo systemctl restart nginx


React app page will be displayed using your public IP.

Step 5: Copy the code to the root folder.

As Nginx is now ready for deployment of our web application. We will copy all of our source code to the nginx root folder '/var/www/html/'.

Path of our source code is 'django-notes-app/mynotes/build/'


We need to copy all these files to nginx root folder

Now refresh the browser and you will get an application UI page.



Step 6: Connect the database

Here API route is missing. In other words, the database is not connected.

For this, we need to add proy_pass to '/etc/nginx/sites-enabled/default ' file as 'location /api { proxy_pass 127.0.0.1:8000/api '









Again Restart the Nginx server for changes to take effect with 'sudo systemctl restart nginx' command and refresh the browser with the IP address as server url.

Now try adding notes in the database.

Also, we can run this app using DNS.









Conclusion:
Nginx is a powerful and popular web server and reverse proxy that can be used to efficiently serve web content and handle high traffic loads. Its modular architecture and extensive configuration options make it highly customizable and adaptable to a variety of use cases.

Nginx is known for its excellent performance and scalability, which makes it a top choice for serving static content, load balancing, and caching. It also has robust security features and can be easily integrated with other tools and technologies such as SSL/TLS encryption, HTTP/2, and Docker.

Overall, Nginx is a reliable and flexible web server that can provide significant benefits to websites and web applications of all sizes.




Comments

Popular posts from this blog

Day 04 — Basic Linux Shell Scripting

Explain in your own words and examples, what is Shell Scripting for DevOps. What is #!/bin/bash? can we write #!/bin/sh as well? Write a Shell Script which prints I will complete #90DaysOofDevOps challenge Write a Shell Script to take user input, input from arguments and print the variables. Write an Example of If else in Shell Scripting by comparing 2 numbers Was it difficult? 1. What is Kernel The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system. 2. What is Shell A shell is special user program which provide an interface to user to use operating system services. Shell accept human readable commands from user and convert them into something which kernel can understand. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal. 3. What is Linux Shell Scripting? A shell script is a

Day 2 Task: Basics Linux command

 Day 2 Task: Basics Linux command Task: What is the linux command to  1. Check your present working directory. 2. List all the files or directories including hidden files. 3. Create a nested directory A/B/C/D/E Ans:- 1. "pwd" is command to check present working directory on linux machine. 2. "ls -la" is command to list all the files or directories including hidden files. in above command, "-l" is use for list the files and directories in long list format with extra information and "a" is use for list all including hidden files and directory in linux machine. 3. To create a nested directory use following command :- "mkdir -p A/B/C/D/E"  "-p" stands for "no error if existing, make parent directories as needed" showing the nested directory in linux machine use "tree" command.. Listing commands - ls -l --> list the files and directories in long list format with extra information - ls -a --> list all inclu