Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to configure virtual host on local web server What i want is when i go to localhost or server IP i want to see the default centos page and when i go to the other websites that are configured in /etc/hosts then i want to see those websites.

Is this the correct configuration for this setup? Its not working as i want..because now all websites go to default centos page which is not what i want.

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@web1.com
    DocumentRoot /var/www/html/
    ServerName localhost
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin webmaster@web1.com
    DocumentRoot /var/www/vhost/web1.com/html/
    ServerName web1.com
    ErrorLog /var/www/vhost/web1.com/logs/error.log
    CustomLog /var/www/vhost/web1.com/logs/access.log common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@web2.com
    DocumentRoot /var/www/vhost/web2.com/html/
    ServerName web2.com
    ErrorLog /var/www/vhost/web2.com/logs/error.log
    CustomLog /var/www/vhost/web2.com/logs/access.log common
</VirtualHost>
share|improve this question
    
This is correct. Two things - restart apache and clear browser cache before refreshing one of your configured sites –  Krzysztof Księżyk Apr 16 '13 at 7:39
    
@Krzysztof Księżyk yes it worked seconds after posting this question..but here is another question i have my /etc/hosts has 192.168.1.5 web1.com, www.web1.com 192.168.1.5 web2.com, www.web2.com to be able to run the websites in local network but i noticed even though in my virtual host configuration i had we1.com and we2.com as the ServerNames why is www.web1.com and www.web2.com but the web1.com and web2.com not working in browser? –  redhatengineer6 Apr 16 '13 at 10:35
add comment

1 Answer

Add this to your virtual host just below ServerName web1.com:

ServerAlias *.web1.com

This is an answer to the comment in your question, you should edit the question to put that question in it.

share|improve this answer
    
i am not sure you read the question/comment well...i put web1.com but then browser recognized www.web1.com and does not web1.com –  redhatengineer6 Apr 16 '13 at 13:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.