logo
Menu

Deploy NGINX with AWS CloudShell and Lightsail In Five Steps

Deploy NGINX with AWS CloudShell in the Lightsail Console.

AWS Admin
Amazon Employee
Published Oct 25, 2023
Last Modified Jun 21, 2024
Have you ever needed to deploy a website, either to support or announce an event? You could use one of the many sites that offer this service, or you could use AWS to deploy your website. Using AWS may seem complicated but there’s a simple way to build websites and deploy other applications using AWS Lightsail. This article show how to deploy a website in five steps with AWS Lightsail and CloudShell.

What is AWS Lightsail and CloudShell?

AWS Lightsail is a service that provides preconfigured Linux and Windows application stacks through an intuitive management console. The preconfigured instances of Virtual Private Servers (VPS), container services, storage, and databases. Networking, access, and security environments are automatically configured to host application. Lightsail bundles all the resources into monthly fixed price, letting you focus on your code and not the cost.
Let’s start by opening the Lightsail console. From the main AWS console, use the search bar to find and launch Lightsail.
Open the Lightsail console using the search function in the AWS Console
We can use the Lightsail console to create and deploy the website, but there’s a faster option.
AWS CloudShell is a browser-based, pre-authenticated shell that you can launch directly from the Lightsail console. With CloudShell, you can run AWS CLI commands without downloading or installing command line tools. To open a terminal, choose CloudShell on the Console Toolbar, in the lower left of the console.
Open CloudShell at the bottom of the Lightsail console
When the command prompt displays, the shell is ready.
The CloudShell terminal

Let's Do This!

Are you ready to build a website? Away we go.

Step 1: Deploy a NGINX on a Virtual Private Server

Lightsail virtual private servers, or instances, include many prebuilt application stacks called blueprints. Lets find the blueprint of NGINX, a popular web server. In the CloudShell terminal, use the get-blueprints command to list all the available blueprints. Because CloudShell includes common Unix/Linux utilities, you can use the unix utility, grep, to filter through the list to find the NGINX blueprint.
All you need is the blueprint-id to create the NGINX instance. Because it's a single page web site, you can use the smallest instance, nano_2_0, which costs $3.50/month. Name the instance and tell AWS which availability zone to use.
When the instance is created, you’ll see a panel for the instance in the Lightsail console.
Lightsail instance panel

Step 2: Configure access to your web server instance

We need to log into the server to deploy and render the web page to a browser. To do this, configure the firewall to open ports for NGINX and the ssh server. Copy the configuration file below and paste it into a text editor. CloudShell includes all the tools you expect in a Linux terminal including the nano editor.
Save the file as ports.json. You can save the file in CloudShell which provides 1 gb of storage.
Saving the ports.json configuration file
We can configure the ports with the Lightsail put-instance-public-ports command, which uploads the ports.json file to the web server Upload the ports.json file and apply it to the VPS.

Step 3: Log into the server and deploy the web page

To login to the web server from the CloudShell terminal download the credentials, or the key-pair. First, make a directory to hold the credentials and then make a request for the key-pair. Set the file permission so that it is readable by only you.
You’ll need the public IP address of the server to login. You can get it from the Lightsail console or you can use the AWS CLI in CloudShell.
Log into the web server using ssh, the default user name for the web server is bitnami.
Replace the NGINX index.html file with the web page below by changing into bitnami content directory and the deleting the default index.html file.
Open a new index.html file in a text editor and paste the web page below.
Save the file as index.html.
Save index.html
At this point, you can open a browser to the public IP of the web server to see the site. However, if the instance is rebooted the server will be assigned a new public IP address. Let’s fix that.

Step 4: Attach a static IP

If the server is restarted, the IP address will change. You can create a static IP and attach it to the web server.

Step 5: Register a domain

Your site should have a memorable address. If you don’t have a domain name, you can create one in Lightsail. Note that domain services are only available in the the us-east-1 region, if you are deploying the server in another region, include the —region us-east-1 parameter in the command.
Let’s register the domain name to AWS Route 53, Amazon’s DNS service. You’ll need the static IP attached to the server, which you can find with the Lightsail get-static-ip command.
Wait one minute, because that’s how long it takes for your domain to propagate word-wide. Open a browser to your website and take it all in.

Step 6: There is no Step 6

You’re done. Walk away from the computer. Enjoy your day.

Summary

Having CloudShell in the Lightsail console is brilliant. You have a complete Linux environment to deploy Lightsail services beyond virtual private servers. Build a container solution, deploy a high availability database, or create more storage for data. You can do this in the CloudShell terminal, and with 1 gb of storage, you can save scripts, configuration files, or even applications. Lightsail is the AWS service for people who want to build in the cloud without having to build the cloud.

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments