Friday, May 15, 2015

Set Up a Virtual Host


1)Root login :-#ssh root@192.168.100.251
2)Create new user:- #adduser demo1
3)Change Password:- #passwd demo1
4)Change Root privileges:- visudo
       
        root    ALL=(ALL)       ALL
     demo1   ALL=(ALL)       ALL


5)su demo1 (Switch user)
6)sudo yum install httpd
7)sudo mkdir -p /var/www/server.lan/public_html
8)sudo chown -R apache:apache /var/www/server.lan/public_html
9)sudo chmod -R 777 /var/www
10)  create a new file called index.html within our configurations directory.

     sudo vi /var/www/server.lan/public_html/index.html

11)add below text to the file index.html

<html>
  <head>
    <title>www.server.lan</title>
  </head>
  <body>
    <h1>Success: You Have Set Up a Virtual Host</h1>
  </body>
</html>


----------------Turn on virtual Host:-

 12)    sudo vi /etc/httpd/conf/httpd.conf

   #Listen 12.34.56.78:80
   #////add hash on Listen 80 & add ip Listen 192.168.100.251:80
   # Listen 80
 Listen 192.168.100.251:80 

NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#   

#   
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
     ServerAdmin webmaster@server.lan
     DocumentRoot /var/www/server.lan/public_html
     ServerName www.server.lan
     ServerAlias server.lan
   #  ErrorLog /var/www/server.lan/error.log
    # CustomLog /var/www/server.lan/requests.log
</VirtualHost>

13)   #sudo systemctl stop httpd.service

14)   #sudo /etc/init.d/httpd start

15) sudo vim /etc/hosts

# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost

#Virtual Hosts
192.168.100.251    www.server.lan

16)check result

curl -I http://192.168.100.251

No comments:

Post a Comment