Installing Nginx on Rocky Linux 9 can be streamlined by directly using the official Nginx repository. This guide will help you set up Nginx efficiently and configure your system to serve content securely and reliably.
Step-by-Step Installation Guide
1. Setting up the Nginx Repository
To install the latest official version of Nginx, you first need to add the Nginx repository to your system. This involves creating a new repository file using vim
.
- Open Terminal.
- Run the following command to create and edit the repository file:
sudo vim /etc/yum.repos.d/nginx.repo
Insert the following configuration into the file:
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
2. Installing Nginx
With the repository in place, proceed to install Nginx:
sudo dnf install nginx
3. Starting and Enabling Nginx
To ensure that Nginx starts automatically at boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Stop/Restart Nginx Server
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl status nginx
4. Configuring Firewall
It is crucial to configure the firewall to allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
🛠️ Nginx Configuration Files and Their Roles
- /etc/nginx/nginx.conf: The main configuration file for Nginx. It includes settings that apply globally.
- /etc/nginx/conf.d/: Directory for domain-specific configuration files. Typically used for server block configurations.
🔍 Conclusion
By following these steps, you have successfully set up Nginx on your Rocky Linux 9 system. This setup not only serves content efficiently but also ensures that your server is secure and reliable. Remember to regularly check for updates to keep your Nginx server up to date!