How to run a single virtual host and run two sites one from main server and second from virtual host.?

Hi i would like two how to run two sites in httpd server . One is running through virtual host and second is running from main configuration directory . i try but i always able to open my virtual sites even type other url. my virtual host site becomes as a default on .
First i want to know is this possible . if yes then help me on this . I am using centos +.httpd server. I am lookinf hear from you geeks .

Yes its possible to run a multiple website in httpd server.

for example:

site1 - www.example1.com (which is running from main directory "/var/www/html/example1.com/

site2 - www.example2.com (which is running from virtual directory "/home/myvirutalhost/example2.com)

  1. create directory in the name of example1.com in /var/www/html/
  2. create directory in the name of log /var/www/html/example1.com

Edit the httpd server configuration file vim /etc/httpd/conf/httpd.conf
3. un-comment the “NameVirtualHost *:80”
4. go to the EOF the file.

<VirtualHost *:80>
ServerAdmin admin@your host.com
DocumentRoot /var/www/html/example1.com
ServerName www.example1.com
ErrorLog /var/www/html/example1.com/logs
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin admin@your host.com
DocumentRoot /home/myvirtualhost/example2.com
ServerName www.example2.com
ErrorLog /home/myvirtualhost/example2.com/logs
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

save & exit

finally check the httpd server syntax by executing the below command

httpd -t

service httpd restart
chkconfig httpd restart

hope this will help you thanks.

2 Likes