Quick Nginx Setup Guide

A comprehensive guide to setting up Nginx on Ubuntu.

1 System Update & Installation

bash
sudo apt update
bash
sudo apt install nginx -y

After installation, verify Nginx is running by accessing your server IP in a browser.

2 Configuring Server Blocks

Replace example.com with your actual domain.

Create Website Directory

bash
sudo mkdir -p /var/www/example.com/html

Set Proper Ownership

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

Set Correct Permissions

bash
sudo chmod -R 755 /var/www/example.com

3 Creating a Sample Page

bash
nano /var/www/example.com/html/index.html
html
<html>
  <head>
    <title>Welcome to example.com</title>
  </head>
  <body>
    <h1>Hi Welcome to Example.com</h1>
  </body>
</html>

4 Nginx Configuration

bash
sudo nano /etc/nginx/sites-available/example.com
nginx
server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com/html;
    index index.html index.htm index.nginx-debian.html;

    server_name example.com www.example.com;

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

5 Final Steps

bash
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
bash
sudo nginx -t
bash
sudo systemctl restart nginx

Video Tutorial

Home Buy Me a Beer

Need a Domain for This Project?

Get your domain name from Namecheap and get it set up with the steps in this guide.

Check Domain Availability

Find Your Domain Name

Check availability on Namecheap — see if your project's domain is ready to register.

Affiliate link — we earn a commission at no extra cost to you.