Search

Step-by-Step Guide: How to Install Nginx on Rocky Linux 9

Welcome to our step-by-step guide on how to install Nginx on Rocky Linux 9. Whether you're a newbie or a seasoned pro, this guide will walk you through the installation process, ensuring you have Nginx up and running smoothly on your Rocky Linux 9 server.

If you're looking to enhance your web server skills or simply need to install Nginx for a specific project, we've got you covered. With our easy-to-follow instructions, you'll be able to set up Nginx on your Rocky Linux 9 machine in no time.

So, let's get started! Follow along to learn how to install Nginx on Rocky Linux 9 and take advantage of its powerful features for your web server.

Why Choose Nginx for Your Web Server?

Nginx is a popular choice for web server software due to its impressive features and advantages. Its speed, efficiency, and compatibility make it stand out among other web server options. Let's explore some of the reasons why you should consider choosing Nginx for your web server:

High Performance and Efficiency

Nginx is known for its exceptional performance and efficiency, making it a preferred choice for websites and web applications that require fast response times. It is capable of handling a large number of concurrent connections with minimal resource usage, ensuring optimal performance even under heavy traffic loads. This efficiency translates to improved user experience and reduced server costs.

Versatility and Flexibility

One of the key advantages of Nginx is its versatility and flexibility. It can be used as a basic web server, a reverse proxy, or a load balancer, depending on your specific needs. Additionally, Nginx offers built-in support for WebSockets and FastCGI, allowing you to easily deploy and manage various types of web applications. Its compatibility with the latest web technologies ensures that your server can handle modern requirements.

Proven Stability and Reliability

Nginx has a reputation for stability and reliability, with a large user base that includes some of the world's busiest websites. The "mainline" branch, recommended for production environments, undergoes regular bug fixes and receives new features, ensuring that Nginx stays up to date and reliable. Its robust architecture and continuous development make it a trusted choice for developers.

By choosing Nginx as your web server, you gain access to a powerful and efficient solution that can enhance the performance and reliability of your websites and web applications. Its speed, versatility, and stability set it apart from other web servers, making it a popular choice among developers worldwide.

Prerequisites for Installing Nginx on Rocky Linux 9

Before you can install Nginx on Rocky Linux 9, there are a few prerequisites that you need to ensure are met. First and foremost, you'll need an internet-connected Rocky Linux machine or server. This will allow you to download the necessary files and packages during the installation process.

Additionally, basic familiarity with the command line is required. You should be comfortable running commands as the root user or with sudo privileges. This will allow you to execute the necessary commands to install and configure Nginx on Rocky Linux 9.

Finally, it's a good idea to have a text editor of your choice installed on your system. This will come in handy when making any configuration changes to Nginx later on. Whether you prefer Vim, Nano, or any other text editor, having one readily available will make the configuration process smoother.

Installing and Enabling the Nginx Repository

Before you can install Nginx on Rocky Linux 9, you need to add and enable the Nginx repository. This will ensure that you have access to the latest version of Nginx during the installation process.

To get started, open a terminal and update your system by running the command sudo dnf update. This will ensure that you have the latest package information.

Once the system is updated, you can proceed to install the "epel-release" software repository by executing the command sudo dnf install epel-release. This repository provides additional packages that are not included in the default Rocky Linux repositories.

After installing the "epel-release" repository, you can enable the Nginx module for the latest version by running the command sudo dnf module enable nginx:mainline. This will allow you to install the mainline version of Nginx, which is recommended for its stability, bug fixes, and new features.

Installing and Running Nginx on Rocky Linux 9

Now that you have enabled the Nginx module, it's time to install and run Nginx on Rocky Linux 9. Follow these simple steps to get started:

Step 1: Installing Nginx

Begin by installing the Nginx package using the command:
sudo dnf install nginx

When prompted, confirm the installation to proceed.

Step 2: Starting and Enabling Nginx

After the installation is complete, start the Nginx service with the following command:
sudo systemctl enable --now nginx

This command not only starts the Nginx service but also ensures that it automatically starts on system reboot.

Step 3: Verifying the Installation

To verify that Nginx is successfully installed and running on Rocky Linux 9, run the command:
nginx -v

This command will display the Nginx version, confirming that the installation was successful.

By following these steps, you have successfully installed and started Nginx on Rocky Linux 9. Now you can leverage the power and efficiency of Nginx for your web server needs.

Configuring the Firewall for Nginx on Rocky Linux 9

Securing your Nginx server is crucial to ensure its safe operation and protect it from unauthorized access. To start, you need to configure the firewall settings on Rocky Linux 9 to allow incoming traffic to your Nginx server. By opening the necessary ports, you can enable communication between your server and other computers.

To configure the firewall, use the firewall-cmd command. If you want to allow HTTP traffic, open port 80 by running the following command:

sudo firewall-cmd --permanent --zone=public --add-service=http

If you require SSL/HTTPS support, open port 443 using the following command:

sudo firewall-cmd --permanent --zone=public --add-service=https

If you prefer to manually open port 443, use the command:

sudo firewall-cmd --permanent --zone=public --add-port=443/tcp

Remember to reload the firewall to apply the changes:

sudo firewall-cmd --reload

By properly configuring the firewall for Nginx on Rocky Linux 9, you can ensure that your web server is accessible to clients while maintaining a secure environment.

Creating a Server User and Configuring the Website Root Folder

When setting up your Nginx server on Rocky Linux 9, it's important to create a separate user to enhance security. To do this, you can use the following commands:

Step 1: Create the Root Folder

First, let's create the root folder where your website files will be stored. Use the command sudo mkdir /usr/share/nginx/html/www to create the folder. Feel free to adjust the folder location based on your specific setup and preferences.

Step 2: Create the Server User

Next, we'll create a user specifically for your Nginx server. Start by creating a new group called "www" with the command sudo groupadd www. Then, create the user "www" and assign it to both the "nginx" and "www" groups using the command sudo adduser -G nginx,www -d /usr/share/nginx/html/www -s /bin/false www. Again, you can modify the folder location as needed.

By creating a separate user and configuring the website root folder, you can ensure better security and organization for your Nginx server on Rocky Linux 9.

Changing Nginx Configuration and Reloading

Once Nginx is installed on Rocky Linux 9, you may need to adjust its configuration to tailor it to your specific needs. To do this, you will need to modify the Nginx configuration file located at /etc/nginx/nginx.conf. Open this file using a text editor of your choice.

Inside the configuration file, you can make changes such as adjusting the number of worker processes, specifying the IP address and port for your server, and configuring various other settings. Take your time to review the available options and customize them according to your requirements.

If you need to create virtual hosts to serve multiple websites, you can create separate configuration files in the /etc/nginx/conf.d/ directory. Each file should contain the necessary directives to define the server blocks for each website. This allows you to host multiple domains or subdomains on a single Nginx instance.

After making changes to the configuration file or creating new virtual host files, you will need to reload the Nginx service to apply the changes. To do this, use the command sudo nginx -s reload. This command will signal the Nginx process to reload its configuration without interrupting any active connections. You should now see the updated settings take effect.

Installing Nginx on Other Linux Distributions

If you're using a different Linux distribution and want to install Nginx, the process may vary slightly from the steps outlined in this guide. However, the overall concepts and principles remain the same. Here, we provide a general overview of how to install Nginx on other Linux distributions.

Step 1: Check Package Manager

Start by identifying the package manager used by your Linux distribution. Common package managers include apt for Debian-based distributions like Ubuntu, dnf for Fedora, and zypper for openSUSE. Once you have determined the package manager, you can proceed with the installation.

Step 2: Update System Packages

Before installing Nginx, it's always a good practice to update your system packages. Run the appropriate command for your package manager to update the system. For example, with apt, you would use sudo apt update && sudo apt upgrade.

Step 3: Install Nginx

Next, you can install Nginx using the package manager. For apt, you can use the command sudo apt install nginx, while for dnf, the command is sudo dnf install nginx. Adapt the command according to your package manager.

Once the installation is complete, you can start and enable the Nginx service using the appropriate commands for your distribution. For example, with Ubuntu, you would use sudo systemctl start nginx to start the service and sudo systemctl enable nginx to enable it to start on boot.

Remember to consult the official documentation and resources specific to your Linux distribution for detailed instructions tailored to your needs.

Conclusion

Congratulations! You have successfully installed Nginx on Rocky Linux 9. Nginx is a powerful and versatile web server that can enhance the performance and reliability of your websites and web applications.

Throughout this guide, you have learned the step-by-step process of installing Nginx and configuring it on Rocky Linux 9. By following the detailed instructions and prerequisites, you now have the knowledge to set up an efficient web server using Nginx.

Take advantage of Nginx's vast range of features, including its ability to act as a reverse proxy, load balancer, and file cache. With its compatibility and stability, Nginx is trusted by developers worldwide.

In conclusion, you have successfully completed the installation of Nginx on Rocky Linux 9. By implementing Nginx, you have taken a significant step towards improving your web server environment and ensuring optimal performance for your websites and web applications.

Sys Admin

Sys Admin

I am a Red Hat Certified Engineer (RHCE) and working as an IT Professional since 2012...