Installation guides

Installing Nginx on RHEL

Step-by-Step Guide

  1. Update the Package Index
    Open a terminal and update the package index to ensure you have the latest information about available packages:
   sudo yum update -y
  1. Install Nginx
    Install Nginx using the yum package manager:
   sudo yum install nginx -y
  1. Start and Enable Nginx
    Start the Nginx service:
   sudo systemctl start nginx

Enable Nginx to start on boot:

   sudo systemctl enable nginx
  1. Adjust the Firewall
    Ensure that your firewall allows HTTP and HTTPS traffic. You can check the current firewall status and add the necessary rules:
   sudo firewall-cmd --permanent --add-service=http
   sudo firewall-cmd --permanent --add-service=https
   sudo firewall-cmd --reload
  1. Verify Nginx Installation
    After the installation is complete, Nginx should start automatically. You can verify this by checking the service status:
   sudo systemctl status nginx

If Nginx is running, you should see an active (running) status.

  1. Test Nginx
    Open your web browser and visit your server’s IP address (http://your_server_ip/). You should see the Nginx default welcome page, indicating that the web server is running correctly.
  2. Configure Nginx (Optional)
    The main configuration file for Nginx is located at /etc/nginx/nginx.conf. You can edit this file to customize your Nginx configuration:
   sudo nano /etc/nginx/nginx.conf

After making changes, restart Nginx to apply them:

   sudo systemctl restart nginx
  1. Enable/Disable Modules
    Nginx uses modules to extend its functionality. You can enable or disable modules by editing the configuration files in the /etc/nginx/modules-enabled/ directory. After enabling or disabling modules, reload Nginx to apply changes:
   sudo systemctl reload nginx
  1. Set Up Server Blocks (Optional)
    Server blocks (similar to Apache’s virtual hosts) allow you to run multiple websites on a single server. To set up a server block, create a new configuration file in the /etc/nginx/conf.d/ directory:
   sudo nano /etc/nginx/conf.d/your_domain.conf

Add the following basic configuration to the file:

   server {
       listen 80;
       server_name your_domain www.your_domain;

       root /var/www/your_domain;
       index index.html index.htm index.php;

       location / {
           try_files $uri $uri/ =404;
       }

       location ~ \.php$ {
           include snippets/fastcgi-php.conf;
           fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
       }

       location ~ /\.ht {
           deny all;
       }
   }

Save and close the file, then restart Nginx to apply the changes:

   sudo systemctl restart nginx
Other Recent Posts