Exercise - Install software on your VM
The last thing we want to try on our VM is to install a web server. One of the easiest packages to install is nginx.
Note
This exercise is optional. If you want to complete this exercise, you'll need to create an Azure subscription before you begin. If you don't have an Azure account or you don't want to create one at this time, you can read through the instructions so you understand the information that's being presented.
Note
In this unit, you use Azure Cloud Shell as a terminal. You can access Cloud Shell through the Azure portal or the Cloud Shell sign-in. You don't have to install anything on your PC or laptop to use it.
Note
Throughout this exercise, replace myResourceGroupName in the examples with the name of an existing resource group, or the name of the resource group that you created for this exercise.
Install NGINX web server
Locate the public IP address of your SampleVM Linux virtual machine.
az vm list-ip-addresses --name SampleVM --output tableNext, open an
sshconnection to SampleVM using the Public IP address from the preceding step.ssh azureuser@<PublicIPAddress>After you're logged in to the virtual machine, run the following command to install the
nginxweb server. The command takes a few moments to complete.sudo apt-get -y update && sudo apt-get -y install nginxExit the Secure Shell:
exit
Retrieve your default page
In Azure Cloud Shell, use
curlto read the default page from your Linux web server by running the following command, replacing<PublicIPAddress>with the public IP you found previously. You can also open a new browser tab and try to browse to the public IP address.curl -m 80 <PublicIPAddress>This command will fail, because the Linux virtual machine doesn't expose port 80 (
http) through the network security group that secures the network connectivity to the virtual machine. We can fix the failure by running the Azure CLI commandvm open-port.Enter the following command into Cloud Shell to open port 80:
az vm open-port \ --port 80 \ --resource-group "myResourceGroupName" \ --name SampleVMIt takes a moment to add the network rule and open the port through the firewall.
Run the
curlcommand again.curl -m 80 <PublicIPAddress>This time, it should return data like the following. You can see the page in a browser as well.
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support, refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>