Nginx is a powerful, high-performance web server widely used for hosting websites, load balancing, reverse proxying, and more. This step-by-step guide will walk you through installing and setting up Nginx on Ubuntu.

Step 1: Update Your System

Before installing any software, update your package lists to ensure you get the latest version of available packages.

sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx

Ubuntu’s default repositories include Nginx, making installation straightforward. Run the following command:

sudo apt install nginx -y

Step 3: Start and Enable Nginx Service

Once installed, start Nginx and enable it to launch at boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 4: Verify Installation

To ensure Nginx is running, check its status:

sudo systemctl status nginx

If Nginx is active, you should see output indicating that it is running.

Step 5: Adjust Firewall Settings (if applicable)

If you have UFW (Uncomplicated Firewall) enabled, allow HTTP and HTTPS traffic:

sudo ufw allow 'Nginx Full'

Check the status to confirm:

sudo ufw status

Step 6: Test Nginx

To verify Nginx is serving pages correctly, open your web browser and enter your server’s IP address:

http://your-server-ip

You should see the default Nginx welcome page.

Step 7: Manage Nginx (Optional Commands)

  • Restart Nginx:sudo systemctl restart nginx
  • Stop Nginx:sudo systemctl stop nginx
  • Reload Nginx (useful after configuration changes):sudo systemctl reload nginx