Hosting multiple web projects web developer

What we are trying to achieve

Purchasing domain <<demo>>.com and then be able to host 2 projects on digital ocean droplet and configuring cloudflare and nginx so that we can

  1. access project1 on the main domain , i.e <<demo>>.com
  2. access project2 using subdomain like project2.demo.com

Highlevel view of what I used :

I used porkbun — to purchase domain , cloudflare’s free tier to manage the domains and digital ocean to host the web projects and configure nginx to route the incoming requests to the right websites.

Step 1 : Domain

If you have a domain then you are all set . If not, you can purchase the domain you want from godaddy or porkbun . I have heard good reviews about porkbun and gave it a try and it was perfect. No-nonsense , user-friendly interface to purchase and manage domains. If you want to try it out along with me , just purchase a domain and accept the verification email .

Step 2 : Digital Ocean Droplet

Create a new account and create a new droplet . There are a lot of ways of creating droplets and digital ocean has some fine articles on the same. For this demo , I have used the digital ocean’s 5$ droplet and took the following steps to create it .

  1. First create the SSH key value pair and upload the SSH key to digital ocean.

Step 3: Checking time

Now, connect to the above droplet using ssh.

Step 4 : Cloudflare for DDOS attacks.

I had a terrible experience with digital ocean as my earlier droplet was dropped because of a DDOS attack . I had used cloudflare in the past and it helps against DDOS attacks.

Run the following commands to configure the main site. 
1) Copy the default config for the main domain
mydomain="<<domain>>.com"sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/$mydomainsudo ln -s /etc/nginx/sites-available/$mydomain /etc/nginx/sites-enabled/$mydomain2) Edit the config file -
vi /etc/nginx/sites-available/$mydomain
The content should look something like thisserver {listen 80;listen [::]:80;root /var/www/project2.<<domain>>.com;index index.html;server_name project2.<<domain>>.com;}Run the following commands to configure the subdomain site.mydomain="<<subdomain>>.com"sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/$mydomainsudo ln -s /etc/nginx/sites-available/$mydomain /etc/nginx/sites-enabled/$mydomain2) Edit the config file -
vi /etc/nginx/sites-available/$mydomain
The content should look something like thisserver {listen 80;listen [::]:80;root /var/www/project2.<<domain>>.com;index index.html;server_name project2.<<domain>>.com;}4. Delete the default available site. sudo rm /etc/nginx/sites-enabled/default5. sudo service nginx restart

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Deepika Gunda

Deepika Gunda

I am a Software Engineer n Tech Enthusiast . You will see me publishing articles on Javascript ,NodeJS and misc.