[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Apache virtual server help needed

Hi

I am trying to set up  2 virtual servers .

my problem is that when I browse wwww.domain1.com it works fine,
but when I go to www.domain2.com. I only see www.domain1.com.
and if I change the order of my virtual hosts, the first domain listed becomes the default domain, and I can't see the second virtual host

I hope this all makes sense

my httpd.conf  looks like this:
NameVirtualHost *:80
<VirtualHost *>
ServerAdmin webmaster@domain1.com
DocumentRoot /home/domain1
ServerName www.domain1.com
</VirtualHost>

<VirtualHost *>
ServerAdmin webmaster@domain2.com
DocumentRoot /home/domain2
ServerName www.domain2.com
</VirtualHost>
0
elric001
Asked:
elric001
  • 10
  • 10
  • 4
1 Solution
 
periwinkleCommented:
Is there a Listen 80 as well?
0
 
periwinkleCommented:
Have you tried:

- using

<VirtualHost *:80>

- using an actual IP address, like:

<VirtualHost xxx.xxx.xxx.xxx:80>

where xxx.xxx.xxx.xxx is an ip address?
0
 
elric001Author Commented:
Is there a Listen 80 as well?
no. I try that
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
elric001Author Commented:
using an actual IP address, like:

<VirtualHost xxx.xxx.xxx.xxx:80>

where xxx.xxx.xxx.xxx is an ip address?>>

yes but I'll try it again <g>.
0
 
elric001Author Commented:
using an actual IP address, like:

<VirtualHost xxx.xxx.xxx.xxx:80>

where xxx.xxx.xxx.xxx is an ip address?>>>>>

Interesting !!
I did this and the brower now points to my
document root setting eg:

DocumentRoot "/var/www/html"

and I still only get the one website.
0
 
periwinkleCommented:
It's something you undoubtedly did, but just in case - you did restart the webserver, correct?
0
 
elric001Author Commented:
It's something you undoubtedly did, but just in case - you did restart the webserver, correct?>>
sure did.
0
 
periwinkleCommented:
Did you try *:80 instead?
0
 
periwinkleCommented:
Also, what happens if you specify the exact IP addresses instead of *.80 in the NameVirtualHost statement?
0
 
WilliamFrantzCommented:
Here's how I setup my virtual hosts:

<VirtualHost *:80>
    ServerName  foo.com
    ServerAlias *.foo.com
    DocumentRoot "/var/www/foo/"
</VirtualHost>

<VirtualHost *:80>
    ServerName  bar.com
    ServerAlias *.bar.com
    DocumentRoot "/var/www/bar/"
</VirtualHost>
0
 
elric001Author Commented:
Also, what happens if you specify the exact IP addresses instead of *.80 in the NameVirtualHost statement?>>
I did that and no change


Here's how I setup my virtual hosts:

<VirtualHost *:80>
    ServerName  foo.com
    ServerAlias *.foo.com
    DocumentRoot "/var/www/foo/"
</VirtualHost>

<VirtualHost *:80>
    ServerName  bar.com
    ServerAlias *.bar.com
    DocumentRoot "/var/www/bar/"
</VirtualHost>
>>>

Hi WilliamFrantz
what does the line Server Alias do ?
I'll add that and see what happens
0
 
elric001Author Commented:
nope still doesn't work.
in the "main Server" part of my httpd.conf I have the following:
ServerName   server.domain1.com

is this OK
0
 
WilliamFrantzCommented:
The server is foo.com, but because of ServerAlias, www.foo.com will also work.  In fact, anything.foo.com will be identical to foo.com.
0
 
WilliamFrantzCommented:
I don't put a "ServerName" statement outside of a <VirtualHost> block.  All my hosts are virtual hosts.

Make sure you have "NameVirtualHost *:80" which is required if you want to configure name-based virtual hosts.

More info on virtual hosts: http://httpd.apache.org/docs/1.3/vhosts/
0
 
elric001Author Commented:
this is so annoying, it's as thought he second virtual host isn't being read.
0
 
periwinkleCommented:
It is acting as if it is not matching the second host.  The first virtual host acts as the default host;  in other words, if nothing matches, it will use the first.
0
 
periwinkleCommented:
Have you tried spelling out the IP address for the FIRST virtual host, and putting the * on the second one?
0
 
periwinkleCommented:
By spelling out, I mean specifying the first virtual host's IP address explicitly.  For the second one, use the *.
0
 
periwinkleCommented:
Also, try putting the ServerName entry first after the VirtualHost statement.
0
 
WilliamFrantzCommented:
> The first virtual host acts as the default host;  in other words,
> if nothing matches, it will use the first.

It seems periwinkle is correct.  I had never tried it before on my server.  I have about a dozen virtual hosts on one server.  If I open a browser to the server IP address instead of naming a particular host, it goes to my first virtual host.

If you swap the order of your virtualhost blocks in httpd.conf, does Apache start serving up the other site?

> Have you tried spelling out the IP address for the FIRST virtual host...

I've never had to do this.  My IP address doesn't appear anywhere in my httpd.conf file.
0
 
elric001Author Commented:
Have you tried spelling out the IP address for the FIRST virtual host, and putting the * on the second one?>>

IT WORKS IT WORKS
I tried using * on both virtual hosts and it works now, also hashed out the ServerName setting.

thanks for your help everyone
0
 
periwinkleCommented:
Awesome!  I wonder which change fixed it for you...
0
 
elric001Author Commented:
If you swap the order of your virtualhost blocks in httpd.conf, does Apache start serving up the other site?>>

the answer to this question is yes.
0
 
elric001Author Commented:
Awesome!  I wonder which change fixed it for you...
I'm not sure, but commenting out the ServerName command seems to have helped.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 10
  • 10
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now