Web applications have gained popularity in recent years as a means of delivering services to various customers. With a web application, you can reach a wider audience, regardless of the device or operating system used.
The ability to install and configure a web server is a valuable skill for both web developers and software developers. A web server is a program that is responsible for serving your web content to clients over the Internet or a network.
Let’s take a look at how to install and configure the Nginx web server on Ubuntu.
Why Use Nginx?
Nginx is a lightweight and powerful web server that can run on both Windows and Linux. In addition to being a web server, Nginx is also widely used as a reverse proxy server and a mail proxy server. Note that Nginx is pronounced as “Engine x”.
As a reverse proxy server, configure Nginx to forward traffic from a specified port to an application running on the server. The Nginx reverse proxy provides an extra layer of security as it inspects and filters the traffic before it hits the server.
Nginx runs as a service or daemon on a server and can be easily managed by service managers such as systemctl on Linux. Last but not least, Nginx is well documented and enjoys tremendous community support.
How to install the Nginx server on Ubuntu
In this guide, we are going to show you how to install the Nginx server on a Linux computer running Ubuntu.
Step 1: install security requirements
If you are installing Nginx on a secure server, it is important that you install these prerequisites to ensure that your installation is secure and that you get stable versions of the programs.
First update your system’s package list.
sudo apt update
To install gnupg2 for a secure communication channel when downloading the application.
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
Next, you should get the official signing key from Nginx to verify the authenticity of the package.
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Now check that the imported file contains the correct key by running:
gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
The output should include the fingerprint as shown below.
Register and set up the Nginx repository on your system to get stable packages, which is important for production and secure environments.
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Step 2: install Nginx
The next step is to install the Nginx server. Remember to update your package sources before downloading new packages.
sudo apt update
Installing the Nginx server is pretty straightforward. Just run the following command:
sudo apt install nginx
Nginx in action
The default page provided by Nginx is saved in the directory / usr / share / nginx / html. You can place your static web pages either in this location or any other location of your choice and configure a virtual host.
With a virtual host, you can serve multiple web pages on the same server hardware or infrastructure.
You can check the status of the Nginx server with the following command:
sudo systemctl status nginx
The output here shows that the Nginx daemon is up and running. If it’s not active, start it with the following command:
sudo systemctl start nginx
If you are making some configuration changes to Nginx, you can use the systemctl command to restart the server as follows:
sudo systemctl restart nginx
To serve the default Nginx webpage, open the url http: // localhost: 80 in a web browser. You will be greeted by a page similar to the following.
Learn how to develop web apps
Congratulations, you have successfully installed and configured Nginx. This guide looked at how to install and configure a web server on Ubuntu. Additionally, we discussed how to use the Nginx server daemon using. manage systemctl.
The demand for web developers has never been so great and shows no signs of slowing anytime soon. Start your web development journey by learning the basics of HTML today.