How to Install Nginx on Linux Mint 19

Nginx is a free, open-source, high-performance HTTP and reverse proxy server responsible for handling the load of some of the largest sites on the Internet.

Nginx can be used as a standalone web server, and as a reverse proxy for Apache and other web servers.

Compared to Apache, Nginx can handle a much large number of concurrent connections and has a smaller memory footprint per connection.

This tutorial will outline the steps required to install Nginx on an Linux Mint 19 machine.


Before starting with the tutorial, make sure you are logged in as a user with sudo privileges and you don’t have Apache or any other web server running on port 80 or 443.

Nginx packages are available in the default Linux Mint repositories. The installation is pretty straightforward.

We’ll start by updating the packages list and then install Nginx:

sudo apt update 
sudo apt install nginx

Once the installation is completed, Nginx service will start automatically. You can check the status of the service with the following command:

sudo systemctl status nginx

The output will look something like this:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-05-29 06:43:26 UTC; 8s ago
     Docs: man:nginx(8)
  Process: 3091 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 3080 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 3095 (nginx)
    Tasks: 2 (limit: 507)
   CGroup: /system.slice/nginx.service
           ├─3095 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─3097 nginx: worker process

Assuming you are using UFW to manage your firewall, you’ll need to open HTTP (80) and HTTPS (443) ports. You can do that by enabling the ‘Nginx Full’ profile which includes rules for both ports:

To verify the status type:

sudo ufw status

The output will look something like the following:

Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)

You can test your new Nginx installation open http://YOUR_IP in your browser of choice, and you will be presented with the default Nginx landing page as shown on the image below:


You can manage the Nginx service in the same way as any other systemd service.

To stop the Nginx service, run:

<code">sudo systemctl stop nginx

To start it again, type:

sudo systemctl start nginx

To restart the Nginx service:

sudo systemctl restart nginx

Reload the Nginx service after you have made some configuration changes:

sudo systemctl reload nginx

By default Nginx service will start on boot. If you want to disable the Nginx service to start at boot:

sudo systemctl disable nginx

And to re-enable it again:

sudo systemctl enable nginx

Nginx Configuration File’s Structure and Best Practices

  • All Nginx configuration files are located in the /etc/nginx directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • To make Nginx configuration easier to maintain it is recommended to create a separate configuration file for each domain. You can have as many server block files as you need.
  • Nginx server block files are stored in /etc/nginx/sites-availabledirectory. The configuration files found in this directory are not used by Nginx unless they are linked to the /etc/nginx/sites-enableddirectory.
  • To activate a server block you need to create a symlink (a pointer) from the configuration file sites in a sites-available directory to the sites-enabled directory.
  • It is recommended to follow the standard naming convention, for example if your domain name is then your configuration file should be named /etc/nginx/sites-available/
  • The /etc/nginx/snippets directory contains configuration snippets that can be included in the server block files. If you use repeatable configuration segments then you can refactor those segments into snippets and include the snippet file to the server blocks.
  • Nginx log files (access.log and error.log) are located in the /var/log/nginx directory. It is recommended to have a different access and error log files for each server block.
  • You can set your domain document root directory to any location you want. The most common locations for webroot include:
    • /home/<user_name>/<site_name>
    • /var/www/<site_name>
    • /var/www/html/<site_name>
    • /opt/<site_name>

You have successfully installed Nginx on your Linux Mint 19. You’re now ready to start deploying your applications and use Nginx as a web or proxy server.

If you have any questions or thoughts to share, don’t forget to leave a comment to reach us.

Leave a Reply