Take your web development projects to the next level with the powerful combination of AWS EC2, React.js, and Nginx.
AWS EC2 (Elastic Compute Cloud) provides an easy way to launch virtual servers and manage resources. It offers flexibility and scalability, allowing you to adjust according to your needs. Moreover, you can enjoy reliable scalability, high availability, and strong security features provided by AWS.
React.js is a widely used JavaScript library that simplifies front-end development. It follows a component-based approach to create interactive user interfaces. With React.js, you can build reusable UI components, improve performance, and deliver a great user experience.
Nginx is a robust web server and reverse proxy that perfectly complements React.js. It delivers fast performance and can handle heavy traffic loads. By utilizing Nginx as a reverse proxy server, you can cache static assets, enhance response times, and easily deploy and manage your React.js applications.
By combining AWS EC2, React.js, and Nginx, you have a winning formula for modern web development. Seamlessly deploy your React.js projects on AWS EC2 instances, take advantage of EC2’s scalability, and optimize performance with Nginx. Unleash the full potential of your web applications with this powerful combination of technologies.
Are you ready to supercharge your web development? Harness the power of AWS EC2, React.js, and Nginx today!
How to Launch an AWS EC2 Instance Easily?
Sign in to the AWS Management Console at https://console.aws.amazon.com.

To open the EC2 service, simply type “ec2” into the search bar at the top of the AWS console. This will help you quickly find and access the EC2 service. By typing “ec2” in the search bar, you can easily locate and use the various features and functions of EC2 available in the AWS console. This convenient search feature makes it easy to find and manage your EC2 instances, network settings, storage options, and security measures. Using the search bar, you can efficiently navigate and control your EC2 environment within the AWS console.

When you open the EC2 service, you will see a list of the EC2 instances you have already launched. These instances are like virtual servers that you have created and are currently running. If you want to create a new EC2 instance, click on the “Launch Instance” button. This will take you to a step-by-step guide that helps you set up and start your new EC2 instance. Just follow the instructions and provide the required information, such as the type of instance you want, network settings, and storage options. This way, you can customize your new EC2 instance to fit your specific needs.

Choose the pre-configured template (AMI) for your instance.
When choosing an instance for your EC2 environment, you can pick from a selection of ready-to-use templates called Amazon Machine Images (AMIs). These templates come with pre-installed software, configurations, and operating systems. By selecting the right AMI, you save time and effort since you don’t have to set up everything from scratch. The AMIs are designed to be user-friendly, allowing you to quickly launch your instance with the desired software and settings already included. You can easily browse through the available options and choose the one that best fits your needs, such as a web server or a database server. This flexibility lets you focus on your actual work instead of spending time on manual setup and installation tasks.

Configure details like network settings and storage options, Set up security groups to control network traffic.
When setting up your EC2 instance, you have the freedom to choose the hardware configuration that best suits your requirements. You can select the type of instance based on factors such as processing power, memory capacity, and storage capacity. This allows you to optimize your instance’s performance for specific workloads.
In addition to hardware selection, you can configure various details for your instance. This includes setting up network settings to define how your instance communicates with the outside world. You can specify the Virtual Private Cloud (VPC) and subnet for your instance, as well as assign it a public IP address if needed. Furthermore, you can customize storage options by choosing the appropriate storage type and size for your instance, whether it’s instance storage, Amazon EBS volumes, or a combination of both.
To ensure the security of your EC2 instance, you can set up security groups. Security groups act as virtual firewalls, controlling inbound and outbound network traffic for your instance. You can define rules that allow or deny specific types of traffic based on protocols, ports, and source/destination IP addresses. This helps protect your instance from unauthorized access and ensures that only the necessary network connections are allowed.
By carefully configuring these details during the setup process, you can tailor your EC2 instance to meet your specific needs in terms of hardware capabilities, network settings, storage options, and security measures.

Select the type of hardware you need for your instance

When setting up your EC2 instance in AWS, you have the option to choose the type of hardware that suits your needs. This includes selecting the right combination of computing power, memory capacity, and storage capabilities for your instance.
The hardware type you choose determines the performance and capabilities of your instance. For example, if you need a powerful instance to run resource-intensive applications, you can select a higher-performance option with more CPU power and memory. On the other hand, if you have lighter workloads, you can choose a more cost-effective option with less computing power.
Selecting the appropriate hardware type allows you to optimize the performance and cost-effectiveness of your EC2 instance, ensuring it meets your specific requirements.
Add storage volumes as needed.

Review your instance configuration.

Optionally, add tags to categorize your instance.
Choose an existing key pair or create a new one for secure access.
To connect to your EC2 instance in a secure way, you need a special file called a private key (.pem file). This key is like a secret password that allows you to access your instance using SSH or other remote access methods. It ensures that only the right people can get into your EC2 instance.
It’s really important to keep the private key safe and not share it with anyone who shouldn’t have access to your EC2 instance. Treat it like a valuable item and store it in a secure place on your computer or a trusted storage location.
By choosing an existing key pair or creating a new one, you’re adding an extra layer of security. This helps make sure that only authorized people can connect to your EC2 instance and keeps it safe from unauthorized access. It’s a smart way to protect your EC2 instance and make sure that only the right people can get in.

Create New Private Key

Review security settings and key pair.
Click “Launch” to start the instance.

Select a key pair for secure connection.
Once launched, you can find the instance’s status and public IP address on the EC2 dashboard.

How to connect to your EC2 instance through SSH Easily?
Please navigate to the search bar of the AWS console, enter “EC2,” and then click on the search result for “EC2.”

After seeing the list of your launched EC2 instances, choose the one you want to connect to.
Click on the instance ID of the selected EC2 instance to proceed.

Once you have clicked on the instance ID of the EC2 instance, you will be able to view the instance summary, including details such as the Public IPv4 address and Private IPv4 addresses.
To continue, find the Connect button at the top-right corner of your screen and click on it.

After clicking on the Connect button, you will see various methods to connect to your EC2 instance. Choose the SSH Client option because we can use this method to upload files to our EC2 instance using SSH. This method requires the private key file (.pem file) that you generated when launching the EC2 instance and saved as the key pair.

After selecting the SSH Client option, you will find the steps for creating a private key. Below that, you will see an SSH command to connect to your instance using its Public DNS.
Copy this command

Next, open your terminal or command line and navigate to the directory where you have stored the private key file (key.pem).

Make sure to copy the command you got earlier and paste it into your terminal or command line. It’s important to double-check the name of your private key file (it should end in .pem) before running the command. This command is crucial because it establishes a secure connection between your computer and the EC2 instance. Once you run the command, your terminal will open a secure channel, allowing you to communicate and control the EC2 instance from your computer.

Once the command is successfully executed, you will be connected to the terminal of your EC2 machine. This means you can interact with the EC2 instance directly through your terminal. You can run commands, manage files, install software, adjust settings, and perform administrative tasks on your EC2 machine. This direct terminal access allows you to control and customize your EC2 instance based on your needs. Now you can proceed with tasks like uploading files, making changes to configurations, or deploying your applications on the EC2 instance.
How to install nginx on your Ubuntu OS?
Update the Packages
Update the Packages in ubuntu operating system by running following command on terminal that connect with EC2 in previous section
sudo apt update
This command updates the package lists, ensuring that you have the latest information about available software packages.
Install Nginx
After updating the package lists, you can proceed to install Nginx by running the following command:
sudo apt install nginx
This command will fetch the Nginx package from the Ubuntu repositories and install it on your system.
Start Nginx Service
Once the installation is complete, you can start the Nginx service using the following command:
sudo systemctl start nginx
This command will start the Nginx service and make your web server accessible.
Verify the Nginx Installation
To ensure that Nginx is running properly, open a web browser and enter your server’s IP address or domain name. If Nginx is installed correctly, you should see the default Nginx landing page.

How to create react js project with create-react-app
Install Node.js and npm
Before creating a React.js project, ensure that you have Node.js and npm (Node Package Manager) installed on your system. You can download and install them from the official Node.js website: https://nodejs.org
Open a Terminal and Install create-react-app
Open a terminal or command line on your system. This is where you’ll run the necessary commands to create and manage your React.js project.
In the terminal, run the following command to install create-react-app
globally on your system:
npm install -g create-react-app
When you run the command npm install -g create-react-app
, it installs a tool called create-react-app
. This tool helps you create the basic structure of a React.js project by running a single command. It sets up all the necessary files and configurations for you, so you can start building your React.js application without worrying about the initial setup.
Create a New React.js Project
Navigate to the directory where you want to create your new React.js project. In the terminal, run the following command:
npx create-react-app first-app
Replace first-app
with the desired name of your project. This command will create a new directory named first-app
(or the name you provided) and set up a basic React.js project structure inside it.



Navigate to the Project Directory
React project is created, navigate to the project folder using the following command:
cd first-app
Start the Development Server
npm start
Make production static build of your react project
run following command to make static build of your project so that you can deploy these files to EC2 server and nginx will serve your static build
npm run build

How to Upload React Build on Ubuntu and serve files using nginx
Upload build Files Ubuntu (EC2 Instance) using scp
To upload the build files of your React application to the root directory of your AWS EC2 instance, make sure your private key file (.pem file) is located in the same folder as the React build files. Then, you can use the following command:
scp -i "key.pem" -r build ubuntu@ec2-44-210-160-56.compute-1.amazonaws.com:~/.
Let’s break down the command:
scp
stands for secure copy, which is a command-line tool for securely transferring files between a local and a remote machine.-i key.pem
specifies the private key file to use for authentication when connecting to the EC2 instance. Replacekey.pem
with the actual name of your private key file.-r build/
indicates that you want to recursively copy the contents of thebuild
directory. This assumes that the React build files are located in a directory namedbuild
in your current directory.ubuntu@ec2-44-210-160-56.compute-1.amazonaws.com
specifies the username (
) and the IP address of your EC2 instance. Replaceubuntu
with the actual IP address of your EC2 instance.ec2-44-210-160-56.compute-1.amazonaws.com
:~/
represents the destination directory on the EC2 instance where you want to upload the files.

Connect Terminal with EC2 instance using SSH
write following command to connect your terminal with aws EC2 instance using SSH, make sure you are in the same directory where private key (.pem) file is located
ssh -i "key.pem" ubuntu@ec2-44-210-160-56.compute-1.amazonaws.com
Let’s break down the command:
ssh
stands for Secure Shell, which is a cryptographic network protocol for secure communication over an insecure network.-i key.pem
specifies the private key file to use for authentication when connecting to the EC2 instance. Replacekey.pem
with the actual name of your private key file.ubuntu@ec2-44-210-160-56.compute-1.amazonaws.com
specifies the username (
) and the IP address of your EC2 instance. Replaceubuntu
with the actual IP address of your EC2 instance.ec2-44-210-160-56.compute-1.amazonaws.com
Move your build folder into var/www/html
execute the following command to move our build folder into var/www/html
directory
sudo mv build/ /var/www/html/
Configure nginx to serve files in build folder
Step 1: Navigate to Nginx Configuration Directory Open a terminal and navigate to the Nginx configuration directory. By default, it is located at /etc/nginx/sites-available/
.
cd /etc/nginx/sites-available
Step 2: Modify the Default Configuration Edit the default configuration file using a text editor. For example, you can use vim:
sudo vim default
Step 3: Configure Nginx to Serve Static Files Inside the configuration file, find the server
block. By default, it starts with server {
. Within this block, locate the location /
directive.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/build;
index index.html;
location /{
root /var/www/html/build;
index index.html;
try_files $uri /index.html;
}
}
Restart nginx server
when you modify configuration files in the /etc/nginx/sites-available
directory, such as the default configuration file, these changes will not be applied immediately. To make sure the changes are implemented and visible, you need to restart the server. Restarting the server allows Nginx to read the updated configuration files and apply the modifications.
By restarting the server, Nginx will use the latest configuration settings, including any changes you made, and serve your website or application accordingly.
execute following command to restart nginx server
sudo systemctl restart nginx
Thank you! Congratulations on successfully launching your EC2 instance, configuring Nginx, and deploying your React app. You’ve accomplished significant milestones in setting up a web server environment and making your application accessible to users.
By launching an EC2 instance, you now have a virtual server that provides the computing resources needed to host your application. Configuring Nginx allows you to efficiently handle incoming requests and serve your React app to users. Deploying your React app means that you have taken the necessary steps to make your application available online and accessible to visitors.
This achievement demonstrates your ability to navigate through various steps involved in launching, configuring, and deploying web applications. It’s a significant milestone in establishing an online presence and delivering your application to users.
Great job, and best of luck with your deployed React app!
Summary
Launching an EC2 instance, configuring Nginx, and deploying a React static build are key steps in setting up a web application on AWS. Let’s break down each step in detail.
To begin, launching an EC2 instance involves creating a virtual server on the AWS cloud platform. You can choose the desired hardware configuration, such as the instance type, CPU, memory, and storage capacity. Once launched, the instance is assigned a unique IP address and is ready to be accessed.
After launching the EC2 instance, the next step is to configure Nginx, a popular web server software. Nginx acts as a middleman between the user’s web browser and the application running on the server. It handles incoming HTTP requests and routes them to the appropriate destination.
To configure Nginx, you first need to connect to the EC2 instance using SSH (Secure Shell). SSH provides a secure channel for accessing the instance remotely. Once connected, you can install Nginx and modify its configuration file to specify how it should handle incoming requests. This includes defining server blocks, specifying domains, and configuring SSL certificates for secure communication.
With Nginx up and running, you can proceed to deploy your React static build. This involves copying the build files to the EC2 instance. The React static build consists of optimized and minified HTML, CSS, and JavaScript files that make up your application. These files need to be placed in a directory that Nginx can access.
To ensure that Nginx serves the React static build, you configure its virtual hosts or server blocks to point to the correct directory where the build files are stored. Additionally, you can set up caching mechanisms and gzip compression for improved performance.
Once the configuration is complete, users can access your React application by entering the EC2 instance’s public IP address or domain name in their web browser. Nginx will receive the incoming requests, route them to the appropriate server block, and serve the corresponding React static build files.
In summary, launching an EC2 instance provides the foundation for hosting your web application. Configuring Nginx ensures proper handling of incoming requests, while deploying the React static build allows users to access and interact with your application. By following these steps, you can successfully set up a robust and scalable web application on AWS.