Prerequisite
- Domain Name - Free(Freenom), Paid(Cloudminister)
- VPS - Centos 7
- 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 Cloudminister.
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 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.
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.
- 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,
<VirtualHost *:80>
DocumentRoot "/var/www/html/learalot.ga"
ServerName learnalot.ga
ServerAlias www.learnalot.ga
<Directory "/var/www/html/learnalot.ga">
Options FollowSymLinks
AllowOverride All
Options -Indexes
Redirect permanent / https://learnalot.ga
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/var/www/html/learnalot.ga"
ServerName learnalot.ga
ServerAlias www.learnalot.ga
<Directory "/var/www/html/learnalot.ga">
Options FollowSymLinks
AllowOverride All
Options -Indexes
</Directory>
</VirtualHost>
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.
- 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
- 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.
Before
After
CONCLUSION- 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.
No comments:
Post a Comment