0%
Loading...
NolimitHost

How to install and configure Nginx

Last updated: March 29, 2026

Tested on: Ubuntu 22.04 & 24.04 LTS. Works on most Linux distributions (Debian, CentOS, etc.) with apt/yum/dnf.

Nginx is a fast, lightweight web server perfect for hosting websites and web applications. This guide covers installation and basic configuration with your own domain.

Prerequisites

  • A VPS with Ubuntu 22.04 or 24.04 LTS
  • Root or sudo access via SSH
  • A domain name (you'll configure DNS after Nginx is set up)
  • 20-30 minutes to complete

Step 1: Update and Install Nginx

Update your system:

sudo apt update && sudo apt upgrade -y

Install Nginx:

sudo apt install -y nginx

Step 2: Open Firewall Ports

Allow HTTP traffic (port 80):

sudo ufw allow 'Nginx HTTP'
sudo ufw allow 22/tcp
sudo ufw enable

Verify the rules:

sudo ufw status

Note: When setting up HTTPS later, you'll also open port 443 (HTTPS).

Step 3: Verify Nginx is Running

Check Nginx status:

sudo systemctl status nginx

Visit http://your.vps.ip.address in your browser to see the Nginx welcome page.

Step 4: Create Your Website Directory

Create a directory for your website files:

sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html

Replace example.com with your actual domain.

Step 5: Create Sample Website Content

Create your index.html file:

nano /var/www/example.com/html/index.html

Add this content:

<!DOCTYPE html>
<html>
  <head>
    <title>Welcome to My Site</title>
  </head>
  <body>
    <h1>Hello from Nginx!</h1>
    <p>Your website is live.</p>
  </body>
</html>

Save with Ctrl+X Y Enter.

Step 6: Configure Nginx for Your Domain

Create a server block configuration for your domain:

sudo nano /etc/nginx/sites-available/example.com

Add this configuration (replace example.com with YOUR domain):

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com/html;
    index index.html;

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

Save the file.

Step 7: Enable Your Site

Enable the server block by creating a symlink:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Remove the default Nginx configuration:

sudo rm /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default

Step 8: Fix Hash Bucket Size

Edit the main Nginx config:

sudo nano /etc/nginx/nginx.conf

Find the line # server_names_hash_bucket_size 64; and uncomment it (remove the #).

Step 9: Test and Reload Configuration

Test the configuration:

sudo nginx -t

You should see:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx to apply changes:

sudo systemctl reload nginx

Step 10: Point Your Domain to Your VPS

In your domain registrar's DNS settings, add an A record:

  • Type: A
  • Name: @ (or your domain)
  • Value: Your VPS public IP address

DNS propagation takes 15 minutes to a few hours. Once complete, visiting your domain in a browser will show your website.

Nginx Management

Check status:

sudo systemctl status nginx

Stop/Start/Restart:

sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx

Enable auto-start on reboot:

sudo systemctl enable nginx

Next Steps

After your website is running:

  • Set up HTTPS/SSL to secure your site
  • Add more content to your website
  • Configure advanced Nginx settings if needed
  • Monitor your server performance with top

Troubleshooting

Configuration test failed? Check for syntax errors in your .conf file. Verify all curly braces and semicolons are correct.
DNS not resolving? Give it time (15 minutes to a few hours) for DNS changes to propagate globally.

Need Help?

For Nginx configuration assistance, please open a support ticket through your billing panel.