Nginx is a powerful and flexible web server that is widely used for serving web content, reverse proxying, caching, load balancing, and more. This guide will walk you through the steps to install and configure Nginx on an AlmaLinux 8.10 system.
Prerequisites
Before you start, ensure you have:
- A running AlmaLinux 8.10 system
- A user account with sudo privileges
- Internet connectivity to download packages
Step 1: Update Your System
First, update your system to ensure all existing packages are up to date.
$ sudo dnf update -y
Step 2: Install EPEL Repository
The EPEL (Extra Packages for Enterprise Linux) repository provides additional packages that are not included in the default repositories. Install EPEL to get access to more software packages.
$ sudo dnf install epel-release -y
Step 3: Install Nginx
With the EPEL repository enabled, you can install Nginx using the dnf
package manager.
$ sudo dnf install nginx -y
Step 4: Start and Enable Nginx
After installing Nginx, start the Nginx service and enable it to start on boot.
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
Step 5: Configure Firewall
If your system has a firewall enabled, allow HTTP and HTTPS traffic to access the web server.
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
$ sudo firewall-cmd --reload
Step 6: Verify Nginx Installation
To verify that Nginx is installed and running correctly, open a web browser and navigate to your server’s IP address. You should see the default Nginx welcome page.
Alternatively, you can use the curl
command to check the Nginx welcome page:
$ curl http://localhost
You should see the HTML content of the Nginx welcome page.
Step 7: Basic Nginx Configuration
Nginx configuration files are located in the /etc/nginx
directory. The main configuration file is /etc/nginx/nginx.conf
, and the default server block configuration file is /etc/nginx/conf.d/default.conf
.
Edit the Default Server Block
To customize your server, edit the default server block configuration.
$ sudo nano /etc/nginx/conf.d/default.conf
You can modify the server block to match your requirements. Here is a basic example:
server {
listen 80;
server_name your_domain_or_IP;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Replace your_domain_or_IP
with your domain name or IP address. Save the file and exit the text editor.
Test Nginx Configuration
Before restarting Nginx, it’s a good practice to test the configuration for any syntax errors.
$ sudo nginx -t
If the test is successful, restart Nginx to apply the changes.
$ sudo systemctl restart nginx
Step 8: Setting Up SSL with Let’s Encrypt (Optional)
For securing your website with HTTPS, you can use Let’s Encrypt to obtain a free SSL certificate. First, install Certbot, the Let’s Encrypt client.
$ sudo dnf install certbot python3-certbot-nginx -y
Use Certbot to obtain and install the SSL certificate.
$ sudo certbot --nginx
Follow the prompts to configure your SSL certificate. Certbot will automatically modify your Nginx configuration to use the SSL certificate.
Step 9: Verify SSL Configuration
After installing the SSL certificate, you can test your site using HTTPS.
$ curl -I https://your_domain_or_IP
You should see HTTP headers indicating a successful HTTPS connection.
Conclusion
You have successfully installed and configured Nginx on your AlmaLinux 8.10 system. Nginx is now ready to serve your web content with high performance and reliability. For more advanced configurations and optimizations, refer to the official Nginx documentation.
Happy hosting!
References
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.