Complete Guide to Installing Nginx on Rocky Linux 9

Complete Guide to Installing Nginx on Rocky Linux 9

1. Environment Preparation

1. System Update

sudo dnf update -y
sudo dnf install epel-release -y

2. Firewall Configuration

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

2. Installing Nginx

  1. Install via EPEL Repository

sudo dnf install nginx -y

2. Verify Installation Version

nginx -v

3. Service Management

  1. Start and Enable on Boot

sudo systemctl start nginx
sudo systemctl enable nginx

2. Check Running Status

sudo systemctl status nginx

4. Basic Configuration

  1. Default Site Directory

/usr/share/nginx/html

2. Main Configuration File Location

/etc/nginx/nginx.conf

3. Test Configuration Validity

sudo nginx -t

5. Access Verification

  1. Access the server IP address in a browser

  2. You should see the Nginx welcome page

6. Optional Configuration

  1. Create a Custom Site

sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html

2. Configure Virtual Host

sudo nano /etc/nginx/conf.d/example.com.conf

7. Security Hardening

  1. Disable Server Version Information Add to nginx.conf:

server_tokens off;

2. Configure SSL Certificate

sudo dnf install certbot python3-certbot-nginx
sudo certbot --nginx

This document provides a complete process from basic installation to production environment configuration, including service management, security settings, and other key steps. For in-depth configurations for specific scenarios (such as load balancing, cache optimization, etc.), you can further expand the configuration modules based on actual needs. It is recommended to always use the <span>nginx -t</span> command to test syntax validity before making configuration changes.

Leave a Comment