In this article, we'll explain how to install Nginx Web Server on AlmaLinux. We will install from source as well as built-in package.
Nginx (pronounced "engine x") is a high-performance and open-source web server software that also functions as a reverse proxy server, load balancer, and HTTP cache. Nginx is known for its exceptional performance and efficiency.
It is designed to handle a large number of concurrent connections. Nginx is a popular choice for many web applications, including e-commerce sites, content delivery networks (CDNs), media streaming services, and much more.
Install Nginx Web Server on AlmaLinux
There are two ways to install Nginx Web server. First way is simple, we just need to execute one command and it gets installed. Second way is installing from source. It is bit complex process and need to have Linux command knowledge.
Let's check the first way of the installation.
Keep the server up-to-date
First, we need to update the server using following command:
sudo dnf update -y
Install Nginx Web Server
Now, execute the following command to install Nginx web server.
sudo dnf install nginx
Add port in firewalld
firewall-cmd --add-port={80,443}/tcp --permanent
firewall-cmd --reload
Start and enable Nginx service
sudo systemctl start nginx
sudo systemctl enable nginx
That's it, we have installed Nginx web server.
Now, let's check the second way of the installation.
Install the dependencies
There are 2 options we can install dependencies. First way is as follow:
sudo dnf groupinstall "Development Tools" -y
Above command will install the all dependencies that required except expat-devel package but it also install unnecessary packages.
Second way is, install necessary packages. We have tested it in normal scenario. If you have any special scenario, the installation process or Apache it may gives error later. If any point you get an error, execute first way.
sudo dnf install expat-devel pcre pcre-devel make gcc openssl-devel python3 autoconf libtool -y
Download the latest release
Now, we need to download the latest release from [official website](https://nginx.org/en/download.html).
wget https://nginx.org/download/nginx-1.24.0.tar.gz
Extract the file
Next, we will extract it and change our working directory. Execute set of following commands:
tar xvzf nginx-1.24.0.tar.gz
cd nginx-1.24.0
Install Nginx Web server
We need to run configure command.
sudo ./configure --prefix=/var/www --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --with-pcre --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-http_ssl_module --modules-path=/etc/nginx/modules --with-http_v2_module --with-stream=dynamic --with-http_addition_module --with-http_gunzip_module
Here we have mentioned different path for different options. With the source installation, we can fully customize the installation with options:
- --with-http_v3_module: Enables building a module that provides support for HTTP/3.
- --with-http_image_filter_module=dynamic: For transforms image.
- --with-http_mp4_module: Server-side support for MP4 files.
- --without-http_empty_gif_module: Disables building a module that emits single-pixel transparent GIF.
- --with-http_perl_module=dynamic: Enables building the embedded Perl module.
And many more. Before using other modules, visit [official document page](https://nginx.org/en/docs/configure.html) to learn more about the modules.
Next, compile and install the files using following commands:
sudo make
sudo make install
Verify the installation
Finally, let's verify the installation. Execute following command:
sudo nginx
Navigate to your browser and access it using your server IP.
Optional
Create few directories
To make it simple we can create 3 new directory in /etc/nginx/. Execute following commands:
cd /etc/nginx/
mkdir {sites-enabled,sites-available,conf.d}
Now, we need to tell Nginx that find configuration and website files in respective directory. Edit nginx.conf file using following command:
vi nginx.conf
Add following lines in http {}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
That's it now you can add and use website and configuration files.
That's it, we have seen how to install Nginx Web Server on AlmaLinux.