0

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>
Oneiroi
  • 2,063
  • 1
  • 15
  • 28
redhatengineer6
  • 79
  • 2
  • 5
  • 9
  • 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 07: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
  • @redhatengineer6 you should update the question, you are now asking a different question and you shouldn't do it in comments. – Luca Gibelli Apr 14 '18 at 22:29

2 Answers2

0

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.

Matt
  • 222
  • 2
  • 8
  • 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
-2

If you're configuring Apache in Ubuntu server, go to the /etc/apache2/sites-available/000-default.conf file and add below lines:

<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>

And add the below lines in host file (/etc/hosts) as well:

127.0.1.1    web1.com
127.0.1.2    web2.com
Nisse Engström
  • 208
  • 2
  • 5