Nginx is one of the world's most popular web servers, known for its speed, reliability, and low resource usage. It is widely used to host websites, reverse proxies, APIs, and web applications on Linux VPS servers.
Requirements
- Ubuntu 24.04 VPS
- Root or sudo access
- SSH access to your server
Step 1 — Update Your VPS
sudo apt update
sudo apt upgrade -y
Step 2 — Install Nginx
sudo apt install nginx -y
Step 3 — Verify Installation
nginx -v
Example output:
nginx version: nginx/1.24.x
Step 4 — Start and Enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
Step 5 — Check Service Status
sudo systemctl status nginx
You should see active (running).
Step 6 — Allow HTTP and HTTPS Through the Firewall
sudo ufw allow 'Nginx Full'
sudo ufw reload
Step 7 — Test Your Web Server
Open your browser and visit:
http://YOUR_SERVER_IP
You should see the default Nginx welcome page.
Useful Nginx Commands
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl stop nginx
sudo systemctl status nginx
Check Configuration Before Reloading
sudo nginx -t
If everything is correct, you will see:
syntax is ok
test is successful
Default Website Directory
/var/www/html
Default Configuration File
/etc/nginx/nginx.conf
Server Block Configuration
/etc/nginx/sites-available/
Best Practices
- Keep Nginx updated to the latest stable version.
- Use HTTPS with a valid SSL certificate.
- Enable HTTP/2 or HTTP/3 when available.
- Test configuration changes before restarting the service.
- Monitor server logs regularly.
Conclusion
Nginx is a lightweight and high-performance web server that is ideal for hosting websites, APIs, and reverse proxies on a VPS. Proper configuration helps improve website speed, security, and reliability.
Related Articles
- How to Install Docker on Ubuntu 24.04 VPS
- How to Install PHP 8.4 on Ubuntu VPS
- How to Secure Your Linux VPS
- How to Enable HTTPS with Let's Encrypt
- How to Connect to Your VPS via SSH
