Install and Configure Nginx on Ubuntu
December 26, 2025
•
5 min read
•
VPS Management
Nginx Installation and Setup
Install Nginx
sudo apt update sudo apt install nginx -y sudo systemctl start nginx sudo systemctl enable nginx
Configure Firewall
sudo ufw allow 'Nginx Full' sudo ufw status
Create Server Block (Virtual Host)
sudo nano /etc/nginx/sites-available/yourdomain.com
Add this configuration:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
}
Enable Site
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
Useful Nginx Commands
# Test configuration sudo nginx -t # Reload without downtime sudo systemctl reload nginx # Restart Nginx sudo systemctl restart nginx # Check status sudo systemctl status nginx # View error logs sudo tail -f /var/log/nginx/error.log
Need Managed VPS?
Skip the setup hassle. WebHostWare Managed VPS comes pre-configured with everything you need.
View VPS Plans