Installing and Configuring NGINX on Ubuntu Servers: A Step-by-Step Guide


NGINX is a popular and high-performance web server that is widely used for serving web applications, handling static content, and acting as a reverse proxy. In this blog post, we will walk you through the process of installing and configuring NGINX on Ubuntu servers. By following these step-by-step instructions, you'll have NGINX up and running on your Ubuntu server in no time.

Are you trying NGINX first time? Checkout the difference between Apache & NGINX here.

Step 1: Update System Packages

Before installing any software, it's essential to update the system packages to the latest versions. Open a terminal on your Ubuntu server and run the following commands:

        $ sudo apt update
$ sudo apt upgrade

Step 2: Install NGINX

NGINX is available in the default Ubuntu repositories, making the installation process straightforward. Run the following command to install NGINX:

        $ sudo apt install nginx

Step 3: Start and Enable NGINX

After the installation is complete, start the NGINX service using the following command:

        $ sudo systemctl start nginx

Additionally, enable NGINX to start automatically at boot time by running the following command:

$ sudo systemctl enable nginx

Step 4: Adjust Firewall Settings

By default, Ubuntu servers have UFW (Uncomplicated Firewall) installed. To allow incoming HTTP and HTTPS traffic to reach NGINX, run the following commands:

$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw allow 'Nginx HTTPS'
$ sudo ufw enable

Step 5: Verify NGINX Installation

You can verify whether NGINX is running correctly by opening a web browser and entering your server's IP address or domain name. If everything is configured properly, you should see the default NGINX welcome page.

Step 6: Adjust NGINX Configuration

NGINX's main configuration file is located at /etc/nginx/nginx.conf. You can make adjustments to this file to customize NGINX's behavior based on your requirements. Some common configuration options include server blocks, SSL settings, proxy configurations, and caching directives. It's recommended to take a backup of the original configuration file before making any changes.

Step 7: Manage NGINX Services

NGINX can be managed using the systemctl command. Some useful commands include:

  • sudo systemctl start nginx - Start the NGINX service

  • sudo systemctl stop nginx - Stop the NGINX service

  • sudo systemctl restart nginx - Restart the NGINX service

  • sudo systemctl reload nginx - Reload NGINX configuration without restarting the service


Installing and configuring NGINX on Ubuntu servers is a straightforward process. By following the steps outlined in this guide, you can have NGINX up and running, ready to serve your web applications and handle web traffic efficiently. NGINX's performance, scalability, and flexibility make it an excellent choice for any web server needs. Customize its configuration based on your requirements to unlock its full potential and enjoy the benefits of this powerful web server.