How to Install and Configure Nginx Web Server on a Linux Server
-
Update System Packages
sudo apt update -
Install Nginx
sudo apt install nginx -
Start Nginx Service
sudo systemctl start nginx -
Enable Nginx on Boot
sudo systemctl enable nginx -
Check Nginx Status
sudo systemctl status nginx -
Open Nginx Configuration File
sudo nano /etc/nginx/nginx.conf -
Edit Configuration File
- Set worker_processes.
- Configure events block.
- Adjust http block.
-
Test Nginx Configuration
sudo nginx -t -
Restart Nginx
sudo systemctl restart nginx -
Allow Nginx Through Firewall
sudo ufw allow 'Nginx Full' -
Create Server Block Directory
sudo mkdir -p /var/www/your_domain/html -
Set Permissions
sudo chown -R $USER:$USER /var/www/your_domain/html -
Create Sample Page
nano /var/www/your_domain/html/index.html -
Edit Server Block File
sudo nano /etc/nginx/sites-available/your_domain -
Add Server Block Content
server { listen 80; server_name your_domain; root /var/www/your_domain/html; index index.html; } -
Enable Server Block
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/ -
Test Configuration Again
sudo nginx -t -
Reload Nginx
sudo systemctl reload nginx -
Check Your Site
- Open browser.
- Visit http://your_domain.
You have installed and configured Nginx.
Sajad Rahimi (Sami)
Innovate relentlessly. Shape the future..
Recent Comments