How to configure Domain Name with VirtualHost in Centos 7 VPS and attach SSL certificate?
Several providers provides Domain Name service to its customer so that people need not remember the IP address of the web server. 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 https://www.freenom.com, you can also purchase it from Godaddy.
Now follow the steps to configure the Domain Name:
- Open the above given website and search for new domain.
- Select the required domain and click on checkout option.
- Now click on Use DNS option and also give the IP address of your VPS, also select the period from 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.
VPS stands for Virtual Private Server are the servers provided by many organizations like AWS, Azure that are used as
Web Server for Website Hosting and Database Server for storing database of all the customer.
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 yourdomain.com
# sudo cd yourdomain.com
# 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 yourdomain.com.conf
- Now write the following code to create Virtual Host,
Redirect Permanent / https://learnalot.ga <—-> If you want to redirect http traffic to https.
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 https://certbot.eff.org/ 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 yourdomain.com 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 Let’s Encrypt Free SSL service provider.