In this section, we will cover the steps required to install NGINX on different operating systems. By the end of this module, you will be able to install NGINX on your system and verify that it is running correctly.
Table of Contents
Installing NGINX on Ubuntu/Debian
Step-by-Step Guide
-
Update the Package List:
sudo apt update
-
Install NGINX:
sudo apt install nginx
-
Start NGINX:
sudo systemctl start nginx
-
Enable NGINX to Start on Boot:
sudo systemctl enable nginx
Explanation
sudo apt update
: Updates the package list to ensure you get the latest version of NGINX.sudo apt install nginx
: Installs NGINX from the default repositories.sudo systemctl start nginx
: Starts the NGINX service.sudo systemctl enable nginx
: Ensures NGINX starts automatically when the system boots.
Installing NGINX on CentOS/RHEL
Step-by-Step Guide
-
Install EPEL Repository:
sudo yum install epel-release
-
Install NGINX:
sudo yum install nginx
-
Start NGINX:
sudo systemctl start nginx
-
Enable NGINX to Start on Boot:
sudo systemctl enable nginx
Explanation
sudo yum install epel-release
: Installs the Extra Packages for Enterprise Linux (EPEL) repository, which contains additional packages including NGINX.sudo yum install nginx
: Installs NGINX from the EPEL repository.sudo systemctl start nginx
: Starts the NGINX service.sudo systemctl enable nginx
: Ensures NGINX starts automatically when the system boots.
Installing NGINX on Windows
Step-by-Step Guide
-
Download NGINX:
- Go to the NGINX download page.
- Download the latest stable version for Windows.
-
Extract the ZIP File:
- Extract the downloaded ZIP file to a directory of your choice, e.g.,
C:\nginx
.
- Extract the downloaded ZIP file to a directory of your choice, e.g.,
-
Run NGINX:
- Open Command Prompt and navigate to the NGINX directory:
cd C:\nginx
- Start NGINX by running:
start nginx
- Open Command Prompt and navigate to the NGINX directory:
Explanation
- Downloading and extracting the ZIP file provides the NGINX binaries for Windows.
- Running
start nginx
in the Command Prompt starts the NGINX server.
Verifying the Installation
Step-by-Step Guide
-
Check NGINX Status:
- On Linux:
sudo systemctl status nginx
- On Windows:
Open a web browser and navigate to
http://localhost
.
- On Linux:
-
Verify NGINX is Running:
- Open a web browser and navigate to
http://localhost
. - You should see the default NGINX welcome page.
- Open a web browser and navigate to
Explanation
sudo systemctl status nginx
: Checks the status of the NGINX service on Linux.- Navigating to
http://localhost
in a web browser verifies that NGINX is running and serving the default page.
Common Issues and Solutions
Issue: NGINX Fails to Start
- Solution: Check the error log for details:
sudo tail -n 20 /var/log/nginx/error.log
Issue: Port 80 is Already in Use
- Solution: Identify and stop the service using port 80:
sudo lsof -i :80 sudo systemctl stop <service_name>
Conclusion
In this section, you learned how to install NGINX on various operating systems, including Ubuntu/Debian, CentOS/RHEL, and Windows. You also learned how to verify that NGINX is running correctly. In the next module, we will explore basic NGINX configuration to customize your web server setup.