This article helps you to create subdomains on DigitalOcean in a few simple steps.
So let’s go to create a simple subdomain.
Step 1: Create a new A Records
Go to the networking section if you are using DigitalOcean else go to your DNS management console.
Let’s create a new A Record with hostname being ex. blog or eCommerce. Where redirect to is the IP address i.e. basically the IP address of the droplet.
Step 2: Create subdirectory & host project files
Create a directory under /var/www/ directory using the commands
sudo nano index.html
When you are inside the index.html file, write anything ex: “Subdomain Working”
Step 3: Configure Virtual Host
Now let’s configure the apche2 virtual host, which will allow our domains to refer to a project directory.
Type in the following commands
cp 000-default.conf subdomain.website.conf
Now once you are inside the config file, change the following
Here, the ServerName is the domain that you want – say eCommerce.mysite.in, ServerAlias is another name using which you want to refer this domain any CNAME in most cases. DocumentRoot is where your project files are located (Root directory of your project)
Point DocumentRoot to the directory where your project files are located.
Save the file Then Run these two commands
- a2ensite subdomain.website.com
- sudo service apache2 restart
Boom, now you can try to access your subdomain.