Introduction:
Nginx is a popular and high-performance web server that is widely used to serve static and dynamic content on the internet. If you’re running Rocky Linux 9 and want to install Nginx to power your website or web application, this step-by-step guide will walk you through the installation process.
Step 1: Update System Packages:
Before installing any new software, it’s essential to ensure that your system packages are up to date. Open a terminal on your Rocky Linux 9 server and execute the following command:
sudo dnf update
This command will update your system packages to their latest versions.
Step 2: Install Nginx:
Once your system is up to date, you can proceed with installing Nginx. Run the following command in the terminal:
sudo dnf install nginx
This command will download and install the Nginx package along with its dependencies.
Step 3: Start Nginx and Enable Auto-Start on Boot:
After the installation is complete, start the Nginx service by running the following command:
sudo systemctl start nginx
To ensure that Nginx starts automatically when the system boots up, enable the Nginx service with the following command:
sudo systemctl enable nginx
Step 4: Verify Nginx Installation:
To confirm that Nginx is installed and running correctly, open a web browser on your local machine and enter your server’s IP address or domain name in the address bar. If you see the default Nginx landing page, it indicates that Nginx has been successfully installed and is serving web content.
Step 5: Configure Firewall:
By default, Rocky Linux uses the firewalld firewall management tool. To allow HTTP (port 80) and HTTPS (port 443) traffic through the firewall and enable web access to your Nginx server, run the following commands:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
Step 6: Adjust SELinux Settings (Optional):
If you are using SELinux, it may be necessary to adjust its settings to allow Nginx to function correctly. To temporarily disable SELinux, run the following command:
sudo setenforce 0
Keep in mind that this is a temporary measure, and it is recommended to properly configure SELinux to work with Nginx for optimal security.
Conclusion:
Congratulations! You have successfully installed Nginx on your Rocky Linux 9 server. Nginx is now ready to serve web content and handle incoming requests. Remember to keep Nginx up to date with regular updates and follow best practices for securing and optimizing your Nginx configuration. With Nginx installed, you have a powerful and reliable web server at your disposal to host your websites and web applications with speed and efficiency.