How to Configure Domain Name With VirtualHost

In this article, learn How to configure Domain Name with VirtualHost in Centos 7 VPS and attach an SSL certificate?

Several providers provide Domain Name service to its customer so that people need not remember the IP address of the webserver. With the help of DNS, the IP address can easily resolve with Domain Name and Vise Versa.


1. Domain Name – Free(Freenom), Paid(Godaddy)

VPS – Centos 7
3. Web Server – apache, nginx

Configure Domain Name

In this blog we are going to take Free Domain Name from, you can also purchase it from Godaddy.

Now follow the steps to configure the Domain Name:

Open the above-given website and search for a new domain.
Select the required domain and click on the checkout option.
Now click on the Use DNS option and also give the IP address of your VPS, also select the period from the top right corner, and then click on continue.

Click On Agree all the Terms and Condition checkbox and complete the shopping.

After that go inside the Domain Name and click on DNS management for your Domain.

Configure VPS

VPS stands for Virtual Private Server are the servers provided by many organizations like AWS, Azure that is used as

Web Server for Website Hosting and Database Server for storing a database of all the customers.

For Example, Centos, Ubuntu, etc.

Now follow the steps to configure VirtualHost in Centos 7 VPS.
1. Open the server with SSH and type sudo command for non-root users.

After that go inside the /var/www/html directory and create new directory over their with the Domain Name by using the following command:

# sudo cd /var/www/html

# sudo mkdir

# sudo cd

# sudo vi index.html

After then write “Website under construction”.

Now create new conf file with server name in conf. directory

# sudo cd /etc/httpd/conf.d

# sudo vi

Now write the following code to create Virtual Host,


DocumentRoot “/var/www/html/”



<Directory “/var/www/html/”>

Options FollowSymLinks

AllowOverride All

Options -Indexes


Redirect Permanent / <—-> If you want to redirect HTTP traffic to HTTPS.


DocumentRoot “/var/www/html/”



<Directory “/var/www/html/”>

Options FollowSymLinks

AllowOverride All

Options -Indexes



And save the file with :wq command.

Configure Web Server

For configuring Web Server you first decide which server you want to use for hosting website, Like apache, nginx, Microsoft IIS select any server based on your requirement.

In this we are going to install apache web server by using the following command:

# yum install -y httpd

# systemctl start httpd

# systemctl enable httpd

Configure SSL certificate

SSL stands for Secure Sockets Layer is a standard security technology for establishing an encrypted connection between the server and the client, Like Mail Server and Web server(Browser) and Mail Client.

Steps to configure the Let’s Encrypt Free SSL certificate in centos7 VPS.
1. Open this URL and click on Get certbot instruction options.

Now select the software and VPS in which your website is running.

Run VPS with SSH and use sudo if you don’t have root privileges.
Enable EPEL repository by using the following command:
# yum install -y

Now after that enable the optional channel by using the following command:

# yum -y install yum-utils

# yum-config-manager –enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

6. Install certbot by using following command:

# yum install certbot python2-certbot-apache

Run this command to get a certificate and have Certbot edit your Apache configuration automatically to serve it, turning on HTTPS access in a single step.

# certbot –apache

Set up automatic renewal

# echo “0 0,12 * * * root python -c ‘import random;

import time; time.sleep(random.random() * 3600)’ && certbot

renew” | sudo tee -a /etc/crontab > /dev/null

Confirm that certbot worked by clicking on the particular website.

Enter your domain name and it will show that website is secured or not.

Test your Domain Name

Now after completing the above installation go to any browser and type the Domain Name in the URL to check the configuration.




In this blog, you can learn how to configure Domain Name with VirtualHost in centos 7 VPS and also learn how to configure SSL certificate in your website by using the Let’s Encrypt Free SSL service provider.

Learn how to scale, manage, and optimize your applications with a SLB. Read our solution brief "Get More from Your Enterprise Network".


Get started with CloudMinister Today