About NGINX
NGINX install on AlmaLinux is a simple process to do it b yourself.
NGINX is popular open-source web server and reverse proxy server.
It is an open-source software program initially designed to solve the challenge of handling lots of connections to servers simultaneously. It was originally designed to make it the fastest web server, but its capabilities expanded significantly beyond being just a web server.
It is known for its high performance, stability, and efficient resource utilization. NGINX is now maintained by NGINX, Inc. It is widely used to serve static content, reverse proxy to application servers, and act as a load balancer.

NGINX Install on AlmaLinux
Before you install NGINX on your AlmaLinux server, here is what you should do first or other words prerequisites
1. Update the system. Ensure your AlmaLinux system is up to date. At the time of writing this guide, AlmaLinux Version 9.3 was the latest. use the below command to update
sudo yum update
2. Check your firewall settings.
If you have the firewall enabled on your system ,make ensure it allows traffic on the ports NGINX will use. Typically ports 80 for HTTP and 443 for HTTPS. You can use the appropriate commands to allow HTTP and HTTPS traffic. We will explore these details during the step-by-step procedure for installation.
NGINX Install on AlmaLinux
It is a easy way NGINX Install on AlmaLinux by following the steps
Open a terminal window on your AlmaLinux system and type the command shown below to install NGINX
sudo yum install nginx
This command uses the yum package manager for AlmaLinux to install the latest version of NGINX.
Enable and start the NGINX service
Enable and start the NGINX service using the following commands after the installation has successfully been completed
sudo systemctl enable nginx — This command configures NGINX to start automatically upon system boot. It creates symbolic links to enable the service.
sudo systemctl start nginx —This command starts the NGINX service immediately. Once executed, NGINX begins running and is available to serve web content.
Open port 80 (HTTP port)
By default, NGINX uses port 80 for HTTP traffic. You must open this port on your system’s firewall for websites to be accessible. The default firewall configuration tool on AlmaLinux is FirewallD. Use these commands to open port 80 and make the changes permanent:
sudo firewall-cmd –zone=public –add-service=http— This command Adds the HTTP service to the firewall’s public zone temporarily. That means it will allow HTTP traffic for the current session.
sudo firewall-cmd –zone=public –add-service=http –permanent — This command permanently adds the HTTP service to the firewall’s public zone, ensuring it persists after a system reboot.
sudo firewall-cmd –reload—This command reloads the firewall configuration, applying any recent changes to ensure these newly added rules take effect immediately.
Verify your NGINX installation
Verify NGINX is properly installed and running as expected. To do open your web browser and navigate to your server’s domain name or IP address. For instance, if your website’s domain name is mysite.com, navigate to http://mysite.com. Or if your IP address is 164.xx.xx.xx, navigate to http://164.xx.xx.xx. If the installation was successfully implemented, you should see the default NGINX welcome page.
NGINX web server configuration
After you install NGINX and verify that everything is successful, here are the website management steps to take to ensure a functioning implementation:
Disabling the default website
Follow these steps to disable the default website:
1. Locate the primary NGINX configuration file /etc/nginx/nginx.conf and open it.
2. Locate the “server” block (in the code) that defines the default website.
3. Using the # character, comment out the root line to prevent NGINX from serving the default web content located in /usr/share/nginx/html. This setup ensures your custom website takes precedence. Your file should look like the one represented in the screenshot shown below
#...
Server{
listen 80 default_server;
listen [::]80 default_server;
server_name _;
#root /usr/share/niginx/html;
#...
Creating a new web server configuration
To create a new server configuration, create a file in the /etc/nginx/conf.d directory with the name of your website, like example.com.conf. Inside the file, define a new server block with the following details:
- listen 80; and listen [::]:80;: — These two lines specify that the server listens for requests on port 80 (HTTP) for both IPv4 and IPv6 connections.
- server_name mysite.com;: — This line defines the domain name for which the server handles requests.
- root /var/www/example.com;: — This line specifies the root directory where NGINX searches for website files.
- index index.html;: — This line defines the default index file to serve when no specific file is requested.
- location / { try_files $uri $uri/ =404; }: — This line specifies a location block that serves the requested file or its index file if it exists, otherwise it returns a 404 error.
After adding the above configurations, the details in your new file should look like those in the screenshot below:
Server{
listen 80;
listen [::]80
server_name example.com;
#root /var/www/html/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Follow the steps below you put up your initial content for the website:
1. To create new website content, you will start by making a directory for your website content using the command sudo mkdir -p /var/www/example.com.
2. Create an index.html file within the directory containing your website’s content. The contents in your index.html should look like those shown below
<!DOCTYPE html> <html> <head> <title> This is a smaple website </title> </head> <body> Hello World! </body> </html>
Change ownership of the website directory by running these two commands in your terminal:
3.1. sudo chown -R nginx:nginx /var/www/example.com
3.2. sudo chmod -R +x /var/www
4. Set the SELinux security context for the website directory to httpd_sys_content_t and httpd_sys_rw_content_t to enable serving web content. To do this, open the terminal and run these commands:
4.1. sudo chcon -t httpd_sys_content_t /var/www/example.com -R
4.2. sudo chcon -t httpd_sys_rw_content_t /var/www/example.com -R
NGINX web server management
After successfully installing NGINX on your AlmaLinux, you need a couple of commands to configure or manage NGINXs functionality and features. It is important to note that NGINX runs on systemd, which essentially means you can manage it using systemctl commands. In this section, we will explore the common systemctl commands that you will use to run NGINX as you prefer.
Enable the NGINX service at startup
To enable the NGINX service at startup, use the below cmd
sudo systemctl enable nginx
This command ensures NGINX automatically starts when the system boots, making your websites or services readily accessible.
Start the NGINX service
To start the NGINX service, use the below cmd
sudo systemctl start nginx
If NGINX isn’t already running, this command starts the service, bringing your websites online.
View the NGINX status
To view the NGINX status, use the below cmd
sudo systemctl status nginx
The current status of the NGINX service is checked using this command, confirming its activity and identifying any potential issues.
Reload the NGINX configuration
To reload the the NGINX configuration, use the below cmd
sudo systemctl reload nginx
If change NGINX’s configuration files, use this command to update the service without interrupting website access.
Restart the NGINX service
To restart the NGINX service, use the below cmd
sudo systemctl restart nginx
This command fully restarts the NGINX service, applying any configuration changes and potentially resolving minor service issues.
Stop the NGINX service
To stop the NGINX service, use the below cmd
sudo systemctl stop nginx
This command stops the NGINX service, making your websites unavailable. Use it for maintenance or troubleshooting purposes.
Disable the NGINX service startup
To disable the NGINX service startup, use the below cmd
sudo systemctl disable nginx
This command prevents NGINX from automatically starting on system boot. One of the scenarios in which this command might be useful for is if you only need NGINX occasionally.
I believe above article will provides information about NGINX Install on AlmaLinux server. To know about raid controller and its types click here.
