Skip to main content

How to Install Nginx on Linux Mint

Nginx is a popular open-source web server that is widely used to serve web content, handle reverse proxying, load balancing, and caching. In this tutorial, we will walk you through the step-by-step process of installing Nginx on Linux Mint. We will cover the installation from the official Linux Mint repositories and guide you through the necessary configurations.

Step 1: Update System Packages.

Before installing Nginx, it's always a good practice to update the system packages to their latest versions. Open the terminal and execute the following command:

sudo apt update && sudo apt upgrade -y

This will update your system packages and ensure that you have the latest versions.

Step 2: Install Nginx.

To install Nginx on Linux Mint, we can use the package manager apt. Run the following command in the terminal:

sudo apt install nginx -y

This command will download and install Nginx along with its dependencies. The -y flag will automatically answer "yes" to any prompts.

Step 3: Start and Enable Nginx.

Once the installation is complete, start the Nginx service by executing the following command:

sudo systemctl start nginx

To ensure that Nginx starts automatically on system boot, enable it with the following command:

sudo systemctl enable nginx

You can verify if Nginx is running by executing the command:

sudo systemctl status nginx

If Nginx is running properly, you should see an output indicating its active status.

Step 4: Firewall Configuration.

By default, Nginx listens on port 80, which is the default HTTP port. If you have an active firewall, you need to allow incoming traffic on port 80 to access your Nginx server. Assuming you are using ufw as your firewall, run the following command in the terminal:

sudo ufw allow 80

This will enable incoming connections to your Nginx server.

Step 5: Testing Nginx.

To test if Nginx is working correctly, open your web browser and enter http://localhost or http://your_server_ip in the address bar. You should see the default Nginx welcome page, confirming that Nginx has been installed successfully.

Step 6: Nginx Configuration Files.

The Nginx configuration files are located in the /etc/nginx directory. The main configuration file is nginx.conf, and additional configuration files are stored in the conf.d directory. You can edit these files to customize Nginx according to your requirements.

Step 7: Virtual Host Configuration.

Nginx allows you to host multiple websites on a single server using virtual hosts. To create a new virtual host configuration, navigate to the /etc/nginx/sites-available directory and create a new configuration file. For example:

sudo nano /etc/nginx/sites-available/example.com

Inside this file, you can configure your website-specific settings, such as server name, root directory, SSL certificates, etc.

Step 8: Enable Virtual Host.

To enable the virtual host you created in the previous step, create a symbolic link from the sites-available directory to the sites-enabled directory. Use the following command:

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

After creating the symbolic link, restart Nginx to apply the changes:

sudo systemctl restart nginx

Your virtual host should now be active and accessible.

Step 9: Additional Nginx Configuration.

Nginx provides various configuration options to optimize performance, enable SSL/TLS, and more. You can explore the official Nginx documentation to learn about these options and customize your server according to your needs.

Step 10: Cleanup.

If you ever need to remove Nginx from your Linux Mint system, execute the following command in the terminal:

sudo apt remove nginx

This will remove Nginx and its associated files from your system.

Congratulations! You have successfully installed and configured Nginx on Linux Mint. You can now start hosting websites or use Nginx for various other purposes.

Remember to regularly update Nginx and your system packages to ensure you have the latest security patches and bug fixes.

Note: This tutorial assumes you have administrative privileges on your Linux Mint system. Some commands may require the use of sudo to execute with root privileges.