Nginx, is an open source web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. It is used frequently in deploying a web app on Virtual Machines and other IaaS services.
We'll be using Microsoft Azure Virtual Machine to deploy an application using the nginx Web Server. We'll also address some common issues that one may encounter during the deployment.
Setting up the Virtual Machine
First of all, we need to have an Ubuntu machine, you can get one from many popular sources including AWS, Azure, Google Cloud, DigitalOcean etc. If you just want to try out the deployment, you can also just use an Ubuntu machine using Virtual Box, VMWare etc. hosted in your own machine.
After setting up the machine and opening the terminal, we should first make sure that our machine is updated using
sudo apt update
sudo apt upgrade
Setting up Nginx Web Server
Now that we have our machine up and running, we can now install the nginx server using
sudo apt-get install nginx
We should also check out our Network Security Group applicable in many cloud service providers and ensure that port 443 (for HTTPS) and port 80 (for HTTP) is enabled. We should also ensure the firewall rules to be allowed for port 443 and 80, we should also make sure that nginx is allowed, we can do that through
sudo ufw allow 443
sudo ufw allow 80
sudo ufw allow 'Nginx Full'
There's no need to do the above steps if
sudo ufw status
returns inactive.
Now we can also enable the nginx server to run when a system boots up and start the server using:
sudo systemctl enable nginx
sudo systemctl start nginx
Setting up the Website
After nginx is set up, we can now clone our website to the machine.
We can now clone our website code in a directory already created by nginx, which is /var/www. We can navigate to the directory using
cd /var/www
If the website is hosted as a git repository, we can directly clone the website repository by using
sudo git clone websiteurlhere.git
and this will automatically create a directory with the name of your repository. Let us assume it is "semikolan" in this case.
If you do not have a Git repository, you can also download a zip file containing code using
sudo wget websiteurl.com/websitecode.zip
and then unzip the code in another folder and then proceed.
Read more here: Installing Nginx on Ubuntu
You can now follow these blogs according to your tech stack:
Laravel: Laravel
And you can set up an SSL certificate using this tutorial.
Top comments (0)