How To install and configure Apache / httpd Name Based Virtual Hosting.
I am using Centos 7.x OS Version and Our Requirement is we need to Create.
Multiple Website in Single server.
Apache Introduction:-
The Apache web server is the most popular web server all over the world. Virtual hosting is a
method for hosting multiple websites (domains) on a single server. You can host multiple websites
on a single machine with a single IP using virtual hosting. All domains on that server will be
sharing a single IP. Virtual hosting is very useful in shared web hosting environments.
where hundreds of websites are hosted on a single dedicated server.
1. Install Apache / Httpd PKG.
# yum install httpd* -y ( For RHEL and Centos )
# apt-get install apache2 -y ( For Ubuntu )
2. Start Apache / Httpd Service
# systemctl start httpd ( For RHEL and Centos )
# systemctl start apache2 ( For Ubuntu )
3. Enable The Service
# systemctl enable httpd ( For RHEL and Centos )
# systemctl enable apache2 ( For Ubuntu )
4. Configure Host File
# vim /etc/hosts ( add host entry for Websites )
192.168.122.11 web1.example.com
192.168.122.11 web2.example.com
192.168.122.11 web3.example.com
5. Create Folders For Websites.
# mkdir /var/www/html/web1
# mkdir /var/www/html/web2
# mkdir /var/www/html/web3
6. Create Web Page For Websites.
# echo "Hi This is my Web1.example.com webSite" > /var/www/html/web1/index.html
# echo "Hi This is my Web2.example.com webSite" > /var/www/html/web2/index.html
# echo "Hi This is my Web3.example.com webSite" > /var/www/html/web3/index.html
7. Go To Apache / Httpd Configuration Directory.
# cd /etc/httpd/conf.d/ ( For RHEL and Centos )
# cd /etc/apache2/sites-available/ ( For Ubuntu )
8. Now Creating The Virtual Host Files
# vim web1.conf
<VirtualHost *:80>
ServerAdmin root@web1.example.com
ServerName web1.example.com
ServerAlias www.web1.example.com
DirectoryIndex index.html
DocumentRoot /var/www/html/web1
# Custom log file locations
LogLevel warn
ErrorLog /var/log/httpd/error-web1.log ==== ( Change the Log Path According to Ubuntu )
CustomLog /var/log/httpd/access-web1.log combined === ( Change the Log Path According to Ubuntu )
</VirtualHost>
Save And Quit File
# cp web1.conf web2.conf
# cp web1.conf web3.conf
Change The All Entry Related To Your Next Website Web2 and Web3 Example:-
ServerAdmin root@web2.example.com
ServerName web2.example.com
ServerAlias www.web2.example.com
DirectoryIndex index.html
DocumentRoot /var/www/html/web2
# Custom log file locations
LogLevel warn
ErrorLog /var/log/httpd/error-web2.log ==== ( Change the Log Path According to Ubuntu )
CustomLog /var/log/httpd/access-web2.log combined === ( Change the Log Path According to Ubuntu )
9. Restart Apache / Httpd Service
# systemctl restart httpd ( For RHEL and Centos )
# systemctl restart apache2 ( For Ubuntu )
10. Open Your Web Browser And Go To The URLs
http://web1.example.com
http://web2.example.com
http://web3.example.com
Comments
Post a Comment