Skip to content

Instantly share code, notes, and snippets.

@kpratikshak
Created February 9, 2026 12:09
Show Gist options
  • Select an option

  • Save kpratikshak/6a970f07fc94d92a21de19810eb75bf8 to your computer and use it in GitHub Desktop.

Select an option

Save kpratikshak/6a970f07fc94d92a21de19810eb75bf8 to your computer and use it in GitHub Desktop.

how to setup a web server using a basic static site served using Nginx. You should also have a basic understanding of how to use rsync to deploy your changes to the server.

What you’ll build

A remote Linux VM (Ubuntu is easiest)

Nginx serving a static site from /var/www/static-site

A local project folder (HTML/CSS/images)

A deploy.sh script that uses rsync to publish changes

(Optional) Domain → server IP + Nginx server_name

  1. Create the remote Linux server

Pick AWS EC2 / DigitalOcean / any provider.

Recommended server specs

Ubuntu 22.04/24.04 LTS

1 vCPU / 1 GB RAM is enough

Open these inbound ports (Firewall / Security Group)

22/tcp (SSH)

80/tcp (HTTP)

(Optional) 443/tcp (HTTPS later)

  1. SSH into the server

From your laptop:

ssh -i /path/to/key.pem ubuntu@<SERVER_PUBLIC_IP>

AWS Ubuntu: ubuntu

AWS Amazon Linux: ec2-user

Debian: admin or debian

  1. Update packages + install Nginx

On the server:

sudo apt update sudo apt -y upgrade sudo apt -y install nginx

Enable and start:

sudo systemctl enable nginx sudo systemctl start nginx sudo systemctl status nginx --no-pager

Test from your browser:

http://<SERVER_PUBLIC_IP> You should see the default Nginx page.

  1. Create a folder for your static site

On the server:

sudo mkdir -p /var/www/static-site sudo chown -R $USER:$USER /var/www/static-site

(We’ll use rsync to push files into this folder.)

  1. Configure Nginx to serve your site

Create a new Nginx site config:

sudo nano /etc/nginx/sites-available/static-site

Paste this (replace domain if you have one; otherwise keep _):

server { listen 80; listen [::]:80;

server_name _;

root /var/www/static-site;
index index.html;

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

# Optional: cache static assets
location ~* \.(css|js|png|jpg|jpeg|gif|svg|ico|webp)$ {
    expires 7d;
    add_header Cache-Control "public, max-age=604800";
    try_files $uri =404;
}

}

Enable the site and disable default:

sudo ln -s /etc/nginx/sites-available/static-site /etc/nginx/sites-enabled/static-site sudo rm -f /etc/nginx/sites-enabled/default

Check config and reload:

sudo nginx -t sudo systemctl reload nginx

Now Nginx will serve whatever is in /var/www/static-site.

  1. Create a simple static website locally

On your local machine, create a folder:

mkdir -p static-site/{assets,css} cd static-site

Create index.html:

<!doctype html>

<title>My Static Nginx Site</title>

✅ Deployed with Nginx + rsync

This site is served from a Linux server.

Logo

Last updated:

<script> document.getElementById("ts").textContent = new Date().toLocaleString(); </script>

Create css/styles.css:

body { font-family: system-ui, Arial, sans-serif; margin: 0; padding: 0; background: #0b1020; color: #e8e8e8; }

.container { max-width: 900px; margin: 60px auto; padding: 24px; background: rgba(255,255,255,0.06); border-radius: 16px; }

.logo { max-width: 180px; display: block; margin: 20px 0; }

.footer { opacity: 0.8; margin-top: 30px; }

Add an image file:

Put any small PNG into static-site/assets/logo.png

(You can use your own image.)

  1. Deploy using rsync (manual command first)

From your local machine, run:

rsync -avz --delete -e "ssh -i /path/to/key.pem" ./ ubuntu@<SERVER_PUBLIC_IP>:/var/www/static-site/

What this does:

-a archive (preserves structure)

-v verbose

-z compress transfer

--delete removes files on server that you deleted locally (keeps exact sync)

Now visit:

http://<SERVER_PUBLIC_IP> You should see your custom page.

  1. Create deploy.sh script (recommended)

In your local static-site/ folder:

nano deploy.sh

Paste (edit values):

#!/usr/bin/env bash set -euo pipefail

SERVER_IP="<SERVER_PUBLIC_IP>" SSH_USER="ubuntu" SSH_KEY="/path/to/key.pem" REMOTE_DIR="/var/www/static-site"

rsync -avz --delete
-e "ssh -i ${SSH_KEY}"
./ "${SSH_USER}@${SERVER_IP}:${REMOTE_DIR}/"

echo "✅ Deployed to ${SERVER_IP}:${REMOTE_DIR}"

Make executable:

chmod +x deploy.sh

Deploy:

./deploy.sh

  1. (Optional) Point a domain name to your server

In your DNS provider:

Create an A record:

@ → <SERVER_PUBLIC_IP>

(Optional) www → <SERVER_PUBLIC_IP>

Then update Nginx server_name:

sudo nano /etc/nginx/sites-available/static-site

Change:

server_name example.com www.example.com;

Reload:

sudo nginx -t && sudo systemctl reload nginx

Quick troubleshooting checklist

Can’t SSH? Check port 22 open + correct username + correct key permissions (chmod 400 key.pem)

Nginx page not showing? Check firewall/security group allows port 80

403/404 errors? ls -la /var/www/static-site

Ensure Nginx root matches: root /var/www/static-site;

Nginx config broken? Always run: sudo nginx -t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment