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 -yStep 2: Install Nginx
Ubuntu’s default repositories include Nginx, making installation straightforward. Run the following command:
sudo apt install nginx -yStep 3: Start and Enable Nginx Service
Once installed, start Nginx and enable it to launch at boot:
sudo systemctl start nginx
sudo systemctl enable nginxStep 4: Verify Installation
To ensure Nginx is running, check its status:
sudo systemctl status nginxIf 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 statusStep 6: Test Nginx
To verify Nginx is serving pages correctly, open your web browser and enter your serverβs IP address:
http://your-server-ipYou 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
