DEV Community

Yuvraj Thapa Chhetri
Yuvraj Thapa Chhetri

Posted on

Nginx Deployment Made Easy: Using AWS App Runner for Web Apps

Image description

If you are planning to deploy your web application on an Nginx server without using complex infrastructure, this blog is for you.

In this blog, I demonstrate how to deploy your web application in a container on a Nginx server using AWS App Runner. AWS App Runner is a fully managed service that simplifies the process of deploying and scaling containerized web applications. So, I used simple web app or a pre-built container image and App Runner handles the rest. It automatically builds, deploys and sets up load balancing with encryption, while scaling up or down based on the traffic needs of your app- making it easy to manage without deep infrastructure expertise.

Why should we use App Runner?

AWS App Runner is a fully managed solution that makes it easier to deploy APIs and containerized web apps. some key reason to use AWS App Runner

  1. Easy to use: App Runner allows you to launch applications directly from source code or container images with little setup, eliminating the need for advanced DevOps knowledge or complex infrastructure configurations.
  2. Scaling: It help to scales applications up or down automatically based on demand, so you don’t need to manage infrastructure capacity.
  3. Cost-effective: Compared to maintaining dedicated infrastructure, you only pay for the resources used when your application is processing traffic, which can help save money.
  4. Default Secure: App Runner automatically implements SSL termination, encryption for data in transit and at rest, and other security best practices.

Let’s go to demo section.

Step 1: Create a pre-built container image

  • Go to Terminal on local machine or VS Code Terminal and type
mkdir nginx-web-app
cd nginx-web-app
Enter fullscreen mode Exit fullscreen mode
  • Now, Open your nginx web app folder in VS code editor or any code editor.

Image description

  • Under Nginx Web App folder create a new file name as index.html and paste it with following code
<!DOCTYPE html>
<html>
<head>
<title>Web Application On Nginx Server</title>
<style>
html { color-scheme: light; }
body { width: 35em; margin: 0 auto;
font-family: Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Congratulation, you are successfully install and configure App runner on AWS cloud. </h1>
<p>If you get this page, the nginx web server is successfully installed and working properly. </p>
<p><em>Thank you for read my blog</em></p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode
  • Now, create another file name Dockerfile and paste it with following code
FROM --platform=linux/amd64 nginx:latest
WORKDIR /usr/share/nginx/html
COPY index.html index.html
Enter fullscreen mode Exit fullscreen mode
  • Now, create container using following command on terminal.
docker build -t nginx-web-app .
Enter fullscreen mode Exit fullscreen mode

Step2: Now, transfer your container image file into Amazon ECR

  • Open your AWS management console and search ECR service

Image description

  • Click on create repository

Image description

  • Write your repository name

  • Leave as default setting and click on create button

Image description

  • After create a repository select your repository and click on view push command

Image description

  • Then paste the following command from push command to your terminal to authenticate and push the image to the repository.

Note: If you are not activate your AWS CLI then you have to configure AWS CLI on your local terminal machine or VS code terminal.

  • Open your terminal and type > aws configure > Paste your credential access key and secret key.

AWS Access Key ID: xxxxxxxxxxxxxxxx
AWS Secret Access Key: xxxxxxxxxxxxx
Default Region: default
Default output format: default

Image description

  • Now, paste the follow the command from view push command.

Image description

Step 3: After complete above process now create AWS App Runner Service

  • create App Runner

Image description

  • For Source and Deployment part leave as default just click on browse

Image description

  • Select your image repository and click on continue

Image description

  • For the deployment part leave as default only select create a new service role under ECR access role

Image description

  • In the service setting part leave as default other setting just change only service name and port then click next

Name: nginx-web-app-service-name
Port:80

Image description

  • Now, in the review and create section just review your setting and click on create and deploy

Image description

  • It will take few minutes you can see logs

Image description

  • When the app is deploying successfully you can copy default domain and paste it browser

Image description

Congratulation! Your web application has now been successfully installed on a Nginx server using AWS App Runner. Scaling and managing your app is now easier and more efficient. Now that load balancing and scaling have been integrated, your application is ready to handle incoming traffic and function effectively at different traffic levels.

Top comments (0)