Posted on

Starting your own website is not rocket science and is very easy to do, even if you are not a techie. And yes, you should have your own site; it's very important.

Get a domain name

Here I am not going to teach you what a domain name is, blah blah; if you want to know, go and check out this link. You go to your favourite site and get a domain. I would suggest Namecheap, which I personally use.

namecheap

Get a vps server

As you are here, I am assuming that you bought your favourite domain name. So now you have to buy a VPS server. If you don't really want to buy, don't worry; there are lots of VPS providers giving us a free trial. Simply go to their website and sign up for the free trial.
Let me tell you their names.

Let's move on to the next step, which is getting a server, once you've signed up for an account with any VPS provider. For this tutorial, I am going to use Linode, but you can use whatever you want.

linode

Click on "Create." After clicking on it, you will see this screen.

linode 2

linode 3

Choose server image(OS), server location and server specs.
Choose strong password and remeber that password because we need that to login into server.
click on create button and wait a few minutes.

linode 3

Let's move on to the next step once that's completed.

Connect your domain with your server

HereHere we will connect the Linode server IP to the domain we purchased earlier.

  • Go to your domain list
  • Select your domain and click on manage domain

dns

  • And move to Advanced Dns option

dns2

  • Now click on "Add New Records" and add A records as shown in the image. And save settings

dns2

  • As you can see we added 4 new records which is 2 A records for ipv4 and 2 AAA records for ipv6
  • You might be wondering where I got these random numbers from, well those are not random numbers.

linode 3

  • Look at the image, where 1 IP is ipv4. I am talking about this 170.187.250.82. IPv6 address is 2400:8904::f03c:93ff:feb2:de74.
  • Note: You put your own IPv4 and IPv6 addresses on your DNS record.
  • Once you Done lets test it.

test

  • When you get output as your server's IP, it means you did everything correctly.

setting up Nginx webserver

Now that the fun part has begun, let's get started. Let's login into our server using ssh.

ssh root@youdomain.com

login

  • After you've logged in, run the commands listed below one by one.
apt update
apt upgrade
apt install nginx
  • Once Nginx has been installed, open your domain and you might see this kind of screen.

login

  • If you are getting an error, don't worry we will fix that.
  • Enable firewall
  ufw allow 80
  ufw allow 443
  • If ufw is not installed please install using apt install ufw
  • If you are intrested to learn about what is Nginx visit link.
  • Now here we are going to create new file /etc/nginx/sites-available by doing this
  nano /etc/nginx/sites-available/mysite
  • nano is command line text editor, you can use any text editor you want. Also you can use whatever name of that file where is used yoursite.
server {
       listen 80 ;
       listen [::]:80 ;
       server_name yourdomain.com ;
       root /var/www/mysite ;
       index index.html ;
       location / {
               try_files $uri $uri/ =404 ;
       }
}
  • You can copy and paste it but don't forget to add your domain in server_name section.
  • Once you done press ctrl+x to exit and type y and hit enter to save.

What is in that code that we added?
Well, listen lines tell Nginx to listen for connections on both IPv4 and IPv6.
The server_name is the website that we are looking for.
root specifies the directory we're going to put our website files in.
index determine what the "default" file is.

Easy and Simple right?

  • Now we have to create the directory and index for the site
  mkdir /var/www/mysite
  • You can name that folder whatever you want, but it must match the name you specified in your configuration file.
  nano /var/www/mysite/index.html
  • Now we made a index file for our site let's add some test content.
  <h1>Test file</h1>
  <p>This is my website</p>
  <p>vikram.wtf</p>
  • We are almost done let's enable this site.
  ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled
  • Now reload Nginx
  systemctl reload nginx

login

Bingo! We are not done yet, we have to get an SSL certificate for our site.

SSl Certificate (enabling https)

We are going to install certbot for SSL certificates.

  • Install command
apt install python3-certbot-nginx
  • Now run this code
certbot --nginx

login

  • After this, you will get a congratulations message. like this;

login

  • Let's check our site

login

  • Bingo! it's working

Now go and write your code and upload to your server using rsync.