DEV Community

starcc
starcc

Posted on

How to Deploy a Simple Website with Nginx: A Comically Easy Guide 🤡

Once upon a time, in a land filled with servers and code, there was an aspiring web developer who dreamt of deploying their simple website to the world. They heard whispers of a powerful tool called Nginx, and so our adventure begins...

Setting the Stage

Before we dive into the magical world of Nginx, let's make sure we have the right tools in our toolbox. You'll need:

  • A server running on Linux (preferably Ubuntu) with root access
  • A simple, static website packed with your creative genius
  • A piping hot cup of coffee/tea/beverage of your choice (optional, but highly recommended)

Summoning the Mighty Nginx

Our hero, the brave web developer, knows that the first step is to install Nginx on their server. They wield their keyboard like a mighty sword and type the following commands:

sudo apt update
sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

With bated breath, they watch as the magical tool installs itself. Once complete, they command Nginx to rise and serve:

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

To ensure the mighty Nginx doesn't slumber after a reboot, they cast a powerful spell:

sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

The Birth of a Virtual Host

The time has come to create a virtual host, the mystical realm where their website shall reside. Our hero crafts a configuration file with the precision of a master artisan:

sudo nano /etc/nginx/sites-available/my-epic-website
Enter fullscreen mode Exit fullscreen mode

Inside this sacred scroll, they write the following incantation:

server {
    listen 80;
    server_name my-epic-website.com www.my-epic-website.com;

    root /var/www/my-epic-website;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
Enter fullscreen mode Exit fullscreen mode

With their masterpiece complete, they save and close the file, creating a symbolic link to bring their virtual host to life:

sudo ln -s /etc/nginx/sites-available/my-epic-website /etc/nginx/sites-enabled/
Enter fullscreen mode Exit fullscreen mode

The Great Migration

Now, our hero must transfer their simple website to the server. They harness the power of the mighty SCP (Secure Copy Protocol) to teleport the files to their new home:

scp -r my-epic-website/ user@server-ip:/tmp/ 
Enter fullscreen mode Exit fullscreen mode

With the files safely on the server, they move them to their final destination:

sudo mv /tmp/my-epic-website/ /var/www/
Enter fullscreen mode Exit fullscreen mode

The Final Test

The moment of truth has arrived. Our hero tests their configuration for any errors:

sudo nginx -t
Enter fullscreen mode Exit fullscreen mode

The gods of Nginx smile upon them, blessing their work with an "OK" status. They reload Nginx to apply the changes:

sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

The Website's Triumph

With a feeling of triumph, our hero types their domain into their browser and beholds the beauty of their simple website, served by the mighty Nginx.

And so our tale comes to an end. With determination and a pinch of comic flair, our hero has deployed their simple website using Nginx. They will be remembered forever as a noble web developer, and their website shall live on in the annals of the internet.

The End.

Top comments (2)

Collapse
 
david_h_0bcb355471a profile image
David Hineman

This made my whole day. There is no finer feeling than conquering the Realm and returning home victoriously!

Collapse
 
filipopo profile image
Filip

This writing style is gold tbh