In this tutorial, we will show you how to install Nginx on AlmaLinux 8. For those of you who didn’t know, Nginx (Pronounce as Engine X) is a powerful web server software that can be used on your server. It is also known for its high performance and low memory usage which will allow fewer resources to be used while getting the job done efficiently. A popular setup is to use it as a proxy for Apache, which can then serve application requests.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nginx on an AlmaLinux 8.
- A server running one of the following operating systems: AlmaLinux 8.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Nginx on AlmaLinux 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf update sudo dnf install epel-release
Step 2. Installing Nginx on AlmaLinux 8.
Now we run the following command to install the Nginx webserver:
sudo dnf install nginx
Once it is installed, you can start and enable the Nginx service using the following command:
sudo systemctl enable nginx sudo systemctl start nginx
After that, we add HTTP and HTTPS ports in the firewall using the following command:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload
Next, verify that the webserver is running and accessible by accessing your server’s IP address:
Step 3. Nginx Configuration File’s Structure.
You don’t need to configure Nginx after successful installation. However, you should know the location of the configuration files and the Nginx root directory in case you need to modify the configuration.
- Nginx configuration directory:
- Nginx root directory:
- Master/Global configuration file:
Step 4. Set up the Nginx Server Blocks.
Nginx server blocks are the same as the Apache virtual hosts, allowing a single server to respond to multiple domain names and serve different content for each of them. In the tutorial, you will set up a domain called your-domian.com, but you should replace this with your domain name. The tutorial will create the web directories and configure the site files in the parent directory
sudo mkdir -p /var/www/your-domain/public_html
Next, set directory permissions:
sudo chown -R $USER:$USER /var/www/your-domain/public_html sudo chmod -R 755 /var/www/your-domain
Then, create a test page server block configuration using your favorite text editor:
Add the following HTML code to the file:
<html> <head> <title>Welcome to your-domain.com</title> </head> <body> <h1>Success! Your Nginx server is successfully configured for <em>your-domain.com</em>. </h1> <p>This is a sample page.</p> </body> </html>
Save and close your file when you are finished, Then create a new server block configuration:
sudo nano /etc/nginx/conf.d/your-domian.com.conf
Add the following file:
Finally, restart Nginx with the following command for the changes to take place:
nginx -t sudo systemctl restart nginx
Now you can test your custom domain setup by typing your domain name in your web browser:
Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the Nginx web server on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official Nginx website.