How to Install and Configure Nginx Web Server on a Linux Server

How to Install and Configure Nginx Web Server on a Linux Server

  1. Update System Packages

    sudo apt update
    
  2. Install Nginx

    sudo apt install nginx
    
  3. Start Nginx Service

    sudo systemctl start nginx
    
  4. Enable Nginx on Boot

    sudo systemctl enable nginx
    
  5. Check Nginx Status

    sudo systemctl status nginx
    
  6. Open Nginx Configuration File

    sudo nano /etc/nginx/nginx.conf
    
  7. Edit Configuration File

    • Set worker_processes.
    • Configure events block.
    • Adjust http block.
  8. Test Nginx Configuration

    sudo nginx -t
    
  9. Restart Nginx

    sudo systemctl restart nginx
    
  10. Allow Nginx Through Firewall

    sudo ufw allow 'Nginx Full'
    
  11. Create Server Block Directory

    sudo mkdir -p /var/www/your_domain/html
    
  12. Set Permissions

    sudo chown -R $USER:$USER /var/www/your_domain/html
    
  13. Create Sample Page

    nano /var/www/your_domain/html/index.html
    
  14. Edit Server Block File

    sudo nano /etc/nginx/sites-available/your_domain
    
  15. Add Server Block Content

    server {
        listen 80;
        server_name your_domain;
        root /var/www/your_domain/html;
        index index.html;
    }
    
  16. Enable Server Block

    sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
    
  17. Test Configuration Again

    sudo nginx -t
    
  18. Reload Nginx

    sudo systemctl reload nginx
    
  19. Check Your Site

You have installed and configured Nginx.

Vibe Plus 1

Sami Rahimi

Innovate relentlessly. Shape the future..

Recent Comments

Post your Comments (first log in)