DEV Community

Francisco Paul Sotelo Rocha
Francisco Paul Sotelo Rocha

Posted on

How to host another page in digital ocean (nginx), with SSL for free (the easy way)

1) Create a folder for every web page in /var/www

To go to /var/www you got to write these lines:
cd ..
cd var/www

In my case i have a folder named html, inside of html y have 3 folders for three different websites i'm hosting, and an index.html that comes for default with nginx

Alt Text

2) Locate the index.html of your project

Yes index with lowercase, not UPPERCASE or something like that, this thing is case sensitive..., in my case my index.html is right here:

Alt Text

you can see the route by writing pwd and then press enter

3) Copy the route

Just copy the route you obtained with pwd

4) Go to sites-available

cd
cd ..
cd etc/nginx/sites-available

right here for default you have a file named default

5) Modify default

you got to modify the file named default, so write this:
vim default
(i use vim, i don't like nano, i'm kind of rebel, don't judge me)

6) Add server block:

right here you're gonna see something like this:

Alt Text

so, after the first
server{

}

write something like this:

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

example example.com (example is just an example, right here you need to write your domain)

root /var/www/example.com (another example, here you need to add the route you just copied with pwd in the 3rd part of this thing)

index index.html (yes, i told you, don't use Index.html, or something like that, that's gonna crash your site)

location / {
try_files $uri $uri =404;
} (for prevent errors)
}

7) Get out of vim

it's not that hard, just press scape, then write :x!, to save the changes you just made

8) Test

Try, that's the way of the jedi (or maybe the way of the sith, you just test it)

sudo nginx -t

you should see something like this in the case you don't have any mistake

Alt Text

9) Install CERTBOT

In the case you don't have certbot you shall install it, this is a guide for install it:

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

10) Add SSL to your webpage

sudo certbot --nginx -d example.com -d www.example.com (again, example is only an example, this is the name of your the name)
this domain should be the same domain you wrote in the block you just wrote, then press 2 because you don't want people in your website not using HTTPS.

And that's all!! Hope it can be usefull

Top comments (0)