This post shows students and new users the steps to install, configure, and use the Nginx HTTP web server on Ubuntu Linux. Nginx is probably the second most popular open source web server in the world. Most likely, many of the websites you visit today are running the Nginx HTTP server.

If you are thinking of running a website, you are more likely to choose Nginx or have Nginx support from web hosting companies than from other web servers. Nginx provides powerful features that can be extended by a wide variety of modules.

If you are a student or a new user learning Linux, the easiest place to start learning is on Ubuntu Linux. Ubuntu is the modern open source Linux operating system for desktops, servers, and other devices.

To start installing the Nginx HTTP server on Ubuntu Linux, follow the steps below.

How to use the Nginx HTTP server on Ubuntu Linux

As mentioned above, Nginx is widely used on the internet. If you want to learn how to install and use it on Ubuntu Linux, continue below.

Nginx is available in the Ubuntu repositories, so we can easily install it using the suitable package management tool.

To install Nginx, run the following commands:

sudo apt update
sudo apt install nginx

The above commands will install the Nginx HTTP server.

Now to find out if Nginx is actually installed and running, use the health check command below.

sudo systemctl status nginx

The command will generate similar lines below when Nginx is running.

YOU CAN ALSO READ:   How to install Skype on Ubuntu Linux

How to allow Nginx through the Ubuntu firewall

If you are running Ubuntu in protected mode with the firewall enabled, you will have to allow HTTP (80) and HTTPS (443) to the Nginx web server. In most cases, the Ubuntu server runs without the firewall enabled. However, run the following commands if you are unsure.

If you are using UFW to manage the Ubuntu firewall, run the following commands to allow traffic.

sudo ufw allow 'Nginx Full'

That will allow full traffic to Nginx.

With the firewall open, simply look up the server’s hostname or IP address to see if the default Nginx page is active.

http://localhost

You should see the default Nginx welcome page.

How to configure Nginx on Ubuntu Linux

Now that Nginx is installed, there are important folders and locations that you should know about. Other Linux systems may have different folder structures and configuration files.

On Ubuntu Linux, these are Nginx configuration files and directory structures.

All Nginx configuration files are located in the / etc / nginx directory. This is considered the Nginx home directory.

The main Nginx configuration file is /etc/nginx/nginx.conf. Global configuration settings are made in the file, but this file is rarely touched.

Nginx Virtual Hosts files are stored in / etc / nginx / sites-available directory. This is the directory where individual websites are defined. Nginx does not use the website settings until they are activated. Once activated, they are linked to the / etc / nginx / sites-enabled directory.

To activate websites to be linked to the / etc / nginx / sites-enable directory, these are the command below. (replace example.com.conf with your VirtualHost file)

sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/

The above command will create a symbolic link to the website configuration files found in the available sites directory to enabled sites directory.

To deactivate a virtual host, use the following command. (replace example.com.conf with your website’s VirtualHost file).

sudo rm /etc/nginx/sites-enabled/example.com.conf

Nginx uses snippets to enhance and add additional functionality and they are found in the / etc / nginx / snippets / directory.

Chunks are only available to load with Nginx when they are contained within a server block.

You can create snippets and store them in the / etc / nginx / snippets directory. To use the fragments within a server block, use the include definition. Example below:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

 include snippets/mycustomsnippets.conf;

........

Nginx also has log files (access.log and error log) are in the / var / log / nginx / directory. You can see the access and error logs in these files in Ubuntu.

There are other Nginx configuration files that may be available in Ubuntu that are not listed above. For more Nginx configurations and how to use it, we will continue to post a valuable tutorial here.

Conclusion:

In this tutorial we have seen how to install and use Nginx on Ubuntu Linux. If you find any errors above or have something to add, use the comment form below.

Write A Comment