How to Install Nginx on Ubuntu, CentOS, and Debian

Install Nginx on Ubuntu

Introduction

Nginx is a powerful and popular web server known for its speed, stability, and flexibility. In this article, we will explore how to install Nginx on three commonly used Linux distributions: Ubuntu, CentOS, and Debian.

Installing Nginx on Ubuntu

Prerequisites

  • A server with Ubuntu operating system installed
  • Access to a user account with sudo privileges

Installation Steps

  1. Update Package Lists
    sudo apt update
  2. Install Nginx
    sudo apt install nginx
  3. Enable and Start Nginx
    sudo systemctl start nginx
    sudo systemctl enable nginx
  4. Configure the Firewall If you are using ufw (Uncomplicated Firewall), allow web server traffic.
    sudo ufw allow 'Nginx Full'
  5. Verify Installation By visiting your server’s IP address in a web browser, you can see the default Nginx landing page.

Installing Nginx on CentOS

Prerequisites

  • A server with CentOS operating system installed
  • Access to a user account with sudo privileges

Installation Steps

  1. Add Nginx Repository
    sudo yum install epel-release
  2. Install Nginx
    sudo yum install nginx
  3. Enable and Start Nginx
    sudo systemctl start nginx
    sudo systemctl enable nginx
  4. Configure the Firewall To allow web server access through the firewall, execute the following commands.
    sudo firewall-cmd --permanent --zone=public --add-service=http
    sudo firewall-cmd --permanent --zone=public --add-service=https
    sudo firewall-cmd --reload
  5. Verify Installation By visiting your server’s IP address in a web browser, you can see the default Nginx landing page.

Installing Nginx on Debian

Prerequisites

  • A server with Debian operating system installed
  • Access to a user account with sudo privileges

Installation Steps

  1. Update Package Lists
    sudo apt update
  2. Install Nginx
    sudo apt install nginx
  3. Enable and Start Nginx
    sudo systemctl start nginx
    sudo systemctl enable nginx
  4. Configure the Firewall If you are using ufw (Uncomplicated Firewall), allow web server traffic.
    sudo ufw allow 'Nginx Full'
  5. Verify Installation By visiting your server’s IP address in a web browser, you can see the default Nginx landing page.

Conclusion

By following the instructions above, you can easily install Nginx on three popular Linux distributions. After installation, you can proceed to further configure Nginx for your web services.

Leave a Reply