NGINX stands out as a premier choice for developers seeking a high-performance, open-source web server solution. Celebrated for its efficiency, minimal resource usage, and ease of configuration, NGINX ensures your web applications and sites run smoothly. It’s the go-to server software for a variety of web serving needs, from simple sites to complex applications.
This guide offers a detailed walkthrough for installing NGINX on two widely-used Linux distributions: Ubuntu and CentOS. Tailored for both new and experienced developers, we aim to simplify the process of setting up NGINX on your Linux system. From initial system updates to configuring the firewall and managing NGINX processes, we’ve got you covered.
Prerequisites
Before you begin, make sure you have:
- A Linux system with root or sudo privileges.
- An internet connection.
- A basic grasp of command-line operations.
Step 1: System Update
Start by updating your system to ensure all existing packages are current. Open your terminal and execute the following:
- For Debian-based systems (like Ubuntu):
sudo apt-get update
- For RHEL-based systems (like CentOS):
sudo yum update
This command refreshes your package lists and prepares your system for new installations.
Step 2: Installing NGINX
Next, install NGINX by running the appropriate command for your distribution:
- For Debian/Ubuntu:
sudo apt-get install nginx
- For RHEL/CentOS:
sudo yum install nginx
Confirm the installation when prompted by typing ‘Y’ and pressing Enter.
Step 3: Confirming NGINX Installation
To verify the successful installation of NGINX, check its version with:
nginx -v
This command displays the current NGINX version installed on your system.
Step 4: NGINX Configuration
NGINX’s configuration files reside in /etc/nginx
, with nginx.conf
being the primary file. This file includes other configurations from the conf.d
directory. Use a text editor to make changes:
sudo vi /etc/nginx/nginx.conf
Adjust the settings as needed and save your changes.
Step 5: Starting and Enabling NGINX
Enable and start the NGINX service so it initiates at boot:
sudo systemctl start nginx sudo systemctl enable nginx
Step 6: Firewall Configuration
Adjust your firewall settings to allow NGINX traffic:
- For Ubuntu/Debian (using UFW):
sudo ufw allow 'Nginx HTTP' sudo ufw reload
- For CentOS/RHEL (using firewalld):
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --reload
Step 7: Testing Your Setup
Check your NGINX installation by navigating to your server’s IP in a web browser. A “Welcome to nginx!” page confirms everything is configured correctly.
Step 8: Managing the NGINX Process
Here are some basic commands to manage your NGINX service:
- To halt NGINX:
sudo systemctl stop nginx
- To initiate NGINX when stopped:
sudo systemctl start nginx
- To restart NGINX:
sudo systemctl restart nginx
- To reload NGINX without dropping connections:
sudo systemctl reload nginx
- To prevent NGINX from starting on boot:
sudo systemctl disable nginx
- To enable NGINX to start at boot again:
sudo systemctl enable nginx
Conclusion
You’ve successfully installed NGINX on your Linux system, setting a solid foundation for your web serving needs. While this guide covers installation and basic management, NGINX’s capabilities extend far beyond. It’s adaptable for a range of scenarios, from serving static content to acting as a reverse proxy. Dive into NGINX’s extensive configuration options to fully leverage its power.