3.0 KiB
Installing Nginx
Prerequisites
Before installing Nginx, ensure that you have root or sudo privileges on your system to carry out installation and configuration commands.
Step-by-Step Installation
For Debian-Based Systems (e.g., Ubuntu)
-
Update Package Repositories
It’s a good practice to update your package repositories before installing new software to ensure you’re downloading the latest version available.sudo apt update -
Install Nginx Install Nginx from the package repository.
sudo apt install nginx -
Start Nginx Service Once installed, start the Nginx service.
sudo systemctl start nginx -
Enable Nginx to Start on Boot This command configures Nginx to start automatically whenever the server reboots.
sudo systemctl enable nginx -
Check Status (Optional) Verify that Nginx is running correctly.
sudo systemctl status nginx
For Red Hat-Based Systems (e.g., CentOS, Fedora)
-
Update Package Repositories As with Debian-based systems, it’s recommended to update repositories first.
sudo yum update -
Install Nginx On Red Hat-based systems, install Nginx with
yum.sudo yum install nginx -
Start Nginx Service Start Nginx after installation.
sudo systemctl start nginx -
Enable Nginx to Start on Boot Configure Nginx to launch automatically on system startup.
sudo systemctl enable nginx -
Check Status (Optional) Confirm that Nginx is running and functioning properly.
sudo systemctl status nginx
Post-Installation Steps
-
Allow Nginx Through the Firewall If your server has a firewall enabled, you may need to allow HTTP (port 80) and HTTPS (port 443) traffic.
Debian-Based Systems:
sudo ufw allow 'Nginx Full'Red Hat-Based Systems:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload -
Verify Installation Open a web browser and navigate to your server’s IP address or domain name:
http://<your-server-ip>You should see the default Nginx welcome page, which confirms that the installation is successful.
Troubleshooting Common Installation Issues
-
Error: Package Not Found
If you encounter an error stating that the Nginx package was not found, you may need to install the EPEL repository (Extra Packages for Enterprise Linux) on Red Hat-based systems:sudo yum install epel-release sudo yum install nginx -
Permission Denied Errors
Ensure you’re usingsudoto run commands that require root privileges. -
Firewall Blocking Access
If you can’t access Nginx via a browser, ensure that firewall rules are configured to allow HTTP/HTTPS traffic.