Skip to main content

Nginx - Host a static website


Let's play with nginx and serve a static website. ;)

Step 1: Install nginx

sudo apt install nginx

Step 2: Update hosts file to add our site name

sudo vim /etc/hosts

Step 3: Unlink default site

cd /etc/nginx/sites-enabled
sudo unlink default

Step 4: Create folder for the site

cd /var/www
sudo mkdir
sudo chmod o+w
echo "coming soon" >

Step 5: Configure nginx

Now we need to nginx where to find our site.

  • sites-available - contains configurations for available sites
  • sites-enabled - contains links to configurations in sites-available. Nginx uses this location to read and run.

sudo vim /etc/nginx/sites-available/

server {

        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/;

        index index.html;


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

Create symbolic link

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the configuration and restart nginx

sudo nginx -t
sudo systemctl restart nginx

Visit our website in the brower