
Nginx is a high-performance, open-source web server that functions as a reverse proxy, load balancer, and HTTP cache. To deploy it on a stable enterprise-grade platform, you can install Nginx Web Server on AlmaLinux 9. It easily handles static and dynamic content and works well with technologies such as PHP and database servers.
In this article, you'll learn how to install and configure Nginx on AlmaLinux 9. The steps include installing Nginx, managing the system service, setting up a custom server block (virtual host), and enabling HTTPS with Let's Encrypt.
Before you begin, you need to:
You can install Nginx on AlmaLinux from the default DNF package sources. It's available using the nginx package name. Use the following steps to update the DNF package manager and install Nginx.
Update system packages.
Install the Nginx web server.
Check that Nginx is installed correctly.
Output:
Start the Nginx service.
Enable HTTP traffic in the firewall.
Run the following command to install Firewalld if it's not installed and allow SSH connections.
Start Firewalld if it's not running.
Apply firewall changes.
Verify that Nginx is working in a browser.
Nginx installs a systemd service by default. Use the following steps to manage the service and ensure it runs consistently on your server.
Enable Nginx to start on boot.
Start Nginx if it isn't already running.
Verify the Nginx system service and confirm that it's running.
Output:
Reload Nginx to apply new configuration changes.
Restart the Nginx service.
Nginx virtual host configurations include the server name, administrator, and the backend web application information. The default.d and conf.d directories contain virtual host configurations for Nginx on AlmaLinux by default unless changed. Follow these steps to create a custom server block with your own HTML content.
Verify the Nginx system service and confirm that it's running.
Set up the document root and create sample content.
Enter the following HTML application code in the index.html file.
Save the file and exit the text editor.
The HTML application displays when the Nginx web server loads all supported files for display in a web browser.
Create a new server block file.
Enter the following Nginx configurations into the example-host.conf file. Replace example.com with your domain.
Save the file and exit the text editor.
The Nginx virtual host configuration serves web application files from the /usr/share/nginx/example directory using the example.com domain.
Test the Nginx configuration syntax for errors.
Output:
Reload Nginx to apply the configuration changes.
Test access to your domain and confirm that the web application loads.
The default server block is stored in the /etc/nginx.conf file. Remove the server block to disable it.
Nginx delivers web applications using HTTP by default unless specified in your virtual host configurations. HTTPS provides encryption between the Nginx and a client's web browser, ensuring secure connections to the web server. This section walks you through installing Certbot, configuring HTTPS, and adjusting SELinux and firewall settings.
Install the EPEL repository, which includes the Certbot tool.
Update your system packages.
Install Certbot with Nginx plugin support.
Request an SSL certificate using Certbot. Replace example.com and admin@example.com with your actual domain and email address.
Replace example.com with your real domain name. If you don't have one, consider using a test domain or skip the SSL setup.
Reload Nginx to apply the HTTPS configuration.
Test the Nginx configuration for syntax errors.
Output:
Allow HTTPS traffic through the firewall.
Optionally, remove HTTP access if you want to enforce HTTPS-only.
Reload Firewalld to apply the new rules.
Check the status of SELinux to ensure it's enabled.
Output:
Install the required SELinux management utilities for the semanage command:
This ensures the semanage tool is available to manage SELinux contexts.
Update SELinux file context rules, enabling Nginx to read files in your custom directory.
The SELinux httpd_sys_content_t context allows Nginx to access files in multiple directories after installation. Allowing access to web application directories enables Nginx to read configurations and application files.
Apply the new SELinux context.
Output:
Access your domain in a web browser using HTTPS to verify that the certificate is working.
You’ve now set up Nginx on AlmaLinux 9, configured it to serve static web content, and secured it with HTTPS and SELinux rules. Nginx is a flexible and high-performance web server that can easily scale to support dynamic web apps, backend integrations like PHP or databases, and production-grade deployments. From here, you can extend your setup by adding reverse proxy rules, enabling load balancing, or integrating with application stacks like Laravel, Flask, or Node.js.
0 Comments
Be the first to comment and share your perspective with the community.