DEV Community

Olalekan Oladiran
Olalekan Oladiran

Posted on • Edited on

HOW TO INSTALL NGINX WEB SERVER ON LINUX VIRTUAL MACHINE

Introduction

NGINX is a popular open-source web server known for its high performance, reliability, and scalability. Initially released in 2004, it has since gained widespread adoption and is commonly used as a web server, reverse proxy server, load balancer, and HTTP cache.

Installing Nginx web server

After creating linux virtual machine, you can install Nginx web server using the following steps:

  1. Find out what IP address your Linux virtual machine is publicly known as using the code: az vm list-ip-addresses --name MyVM --output table. The name of the virtual machine created virtual machine is MyVM Image description
  2. After obtaining the Public IP address from the previous step, establish an SSH connection to MyVM using the code ssh azureuser@ip-address

Image description
3.To install the nginx web server, enter the following command after logging into the virtual machine. It will take a few moments to finish the command.
sudo apt-get -y update && sudo apt-get -y install nginx
Image description

  1. quit the secure shell using the code exit Image description

How to get default webpage

  1. To access the default page from your Linux web server using curl in Azure Cloud Shell, use the following command, changing to the public IP you previously discovered. Another option is to try opening a new tab in your browser and accessing the public IP address. curl -m 80

Image description

Image description
The reason this command fails is that the network security group that protects the virtual machine's network connectivity does not allow the Linux virtual machine to expose port 80 (http). By using the Azure CLI command vm open-port, we can resolve the issue.

  1. To open port 80 in Cloud Shell, enter the following command: az vm open-port \ --port 80 \ --resource-group MyResourceGroup \ --name MyVM

Image description

  1. Use the curl command once again.

Image description
This time, the following data should be returned. The page is also visible in a browser by searching the ip address in a browser.

Image description

Top comments (0)