June 17, 2020

I'm gonna out on a limb here and assume that you know the basics of how a web server works when you clicked on the title of this post. Basic knowledge of vim would be helpful too.

For help if you get stuck, look at the Note at the bottom of this post.

This tutorial is specifically aimed for Unix users but anyone can follow this in all honesty. Yeah, even the Windows users!👌🏻

Alright, so first of all you wanna make sure that you have a web server up and running. You can use Apache2 but for better security and anonymity, I'd recommend that you use Nginx. It's pretty cool :P

Step 1 - Setting up the Nginx server

To check for its installation, type nginx into the terminal. And head to localhost:8080 in your preferred web browser.

If you don't have it installed, you can go ahead and install it using brew install nginx on your macOS or sudo apt-get install nginx on your WSL or Linux distro with Debian packages.

Once you have it installed, run it using nginx and head to the localhost:8080 in your browser. If it shows something similar to :


Once you are sure that Nginx is installed and runs fine, move on to the next step.

Step 2 - Configuring the Nginx config file ( Optional )

Let's say you are already hosting something on localhost:8080 and don't want to set up Nginx on that port, you'd want to change the Nginx config file in that case.

arthtyagi@MacBook-Pro ~ % cd /usr/local/etc/nginxarthtyagi@MacBook-Pro ~ % vim nginx.conf

( Note: If you don't like how your vim is, check this vimconfig out. )

 84     #server {
 85     #    listen       8000;
 86     #    listen       somename:8080;
 87     #    server_name  somename  alias  another.alias;
 89     #    location / {
 90     #        root   html;
 91     #        index  index.html index.htm;
 92     #    }
 93     #}

Uncomment these lines to open port 8000 for Nginx and while you are at it, don't forget to comment out port 8080 lines cause you don't want Nginx listening on two ports, that just doesn't work.

Once you're satisfied with your configuration, move on to Step 3.

Step 3 - Serving static content.

arthtyagi@MacBook-Pro ~ % cd /usr/local/var/wwwarthtyagi@MacBook-Pro ~ % vim index.html