Sunday, 7 February 2016

Name based Virtual Hosting



Step 1: Create Dir for Document root to Keep web pages for multiple domains and copy webpagescontents on it:



[root@linuxcnf ~]# mkdir /var/www/html/domain1.com

[root@linuxcnf ~]# mkdir /var/www/html/domain2.com

Step 2: Provide selinux permission if selinux is enforcing mode:

[root@linuxcnf ~]# chcon –R -t httpd_sys_content_t /var/www/html/domain1.com/

[root@linuxcnf ~]# chcon -R –t httpd_sys_rw_content_t /var/www/html/domain2.com

Step 3: Add the below configuration in end the file:

[root@linuxcnf ~]# vi /etc/httpd/conf/httpd.conf

# Virtual hosts

Include conf.d/*.conf

Step 4: Open or create new fileby issue below command:

[root@linuxcnf ~]# vi /etc/httpd/conf.d/httpd-vhosts.conf

#Add these lines in the file
NameVirtualHost *:80

<VirtualHost *:80>

    ServerAdmin root@domain1.com

    DocumentRoot "/var/www/html/domain1.com"

    ServerName domain1.com

    ServerAlias www.domain1.com

    ErrorLog "/var/log/httpd/domain1.com-error_log"

    CustomLog "/var/log/httpd/domain1.com-access_log" common

</VirtualHost>

<VirtualHost *:80>

    ServerAdmin root@domain2.com

    DocumentRoot "/var/www/html/domain2.com"

    ServerName domain2.com

    ServerName www.domain2.com

    ErrorLog "/var/log/httpd/domain2.com-error_log"

    CustomLog "/var/log/httpd/domain2.com-access_log" common

</VirtualHost>

:wq  #To save the file

Step 5: You can check the contents with below command if there is any error in configuration files:

[root@linuxcnf ~]# httpd -t


Step 6: After all the configuration needs to restart services:

[root@linuxcnf ~]# service httpd restart


That's it!!!!!!!!!!!!!

No comments:

Post a comment