Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1 IP / Multiple sites - Apache 2.0

Status
Not open for further replies.

rrsub

MIS
Oct 23, 2002
536
US
I've seen this time and time again but I must be doing something wrong. I know how to do it in IIS but I need some pushing in the right direction for Apache.

Apache 2.0.43
2(+) websites 1 IP address

Here's my directives:

<VirtualHost *>
DocumentRoot &quot;/Volume2m/Websites/website1.com&quot;
ServerName website1.com
ServerAlias ww2.website1.com
</VirtualHost>

<VirtualHost *>
DocumentRoot &quot;/Volume2m/Websites/website2.com&quot;
ServerName website2.com
ServerAlias ww2.website2.com
</VirtualHost>

Right now, both sites view the first VHost site. If I change <VirtualHost *.website1.com> the sites default to the apache default site.

What's wrong?
 
Try this:

<VirtualHost *>
DocumentRoot /Volume2m/Websites/website1.com/
ServerName website1.com
ServerAlias ww2.website1.com
</VirtualHost>

<VirtualHost *>
DocumentRoot /Volume2m/Websites/website2.com/
ServerName website2.com
ServerAlias ww2.website2.com
</VirtualHost>

Let me know how that works out for you.
 
Not sure about 2.x, but make sure you have a NameVirtualhost directive and see faq65-1831
 
Serbtastic:

Your recommendation didn't work. Website2 still defaults to Website1.
Little more info, site1 has index.php, site2 has index.html (as default docs).

If I comment out site1 directives, then site2 works.

The other thing that's weird is that if I use the IP address, I still get site1 and not the Apache welcome page as if I had no site.


SMAH:

Uncommenting the NameVirtualHost directive gives this error:

[error] VirtualHost _default_:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
 
Find your VirtualHost _default_:443 directive and change it to VirtualHost *:443[/b]. If it's not in httpd.conf, it may be in commonhttpd.conf or something similar. Then try again with the NameVirtualHost.
 
I really should preview first....

Find your VirtualHost _default_:443 directive and change it to VirtualHost *:443. If it's not in httpd.conf, it may be in commonhttpd.conf or something similar. Then try again with the NameVirtualHost.
 
smah:

located in ssl.conf; still get the error

[error] VirtualHost *:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results

now sites won't load.
 
Answer here:

Enable NameVirtualHost and give it the server IP address.

Under Vhost directives:
<VirtualHost 10.0.0.20>

</VirtualHost>

Add the IP address.

unnamed headers resolving to the IP address will display the first VHost site. (That's OK, just create a dummy site for the first site)
 
I am new to apache and the web server stuff. I just last seekend installed apache for the first time. I got the server up in no time but it tooke me 3 days to get two domains going at the same time. I finally did it like this.

NameVirtualHost website1.com:80

<VirtualHost website1.com:80>
DocumentRoot &quot;/Volume2m/Websites/website1.com&quot;
ServerName website1.com
ServerAlias ww2.website1.com
</VirtualHost>

<VirtualHost website1.com:80>
DocumentRoot &quot;/Volume2m/Websites/website2.com&quot;
ServerName website2.com
ServerAlias ww2.website2.com
</VirtualHost>


I used the domain name of the main server or primary server to replace the asterisk and appended the port to it. I am using a dynamic ip router service on a dialup connection. since the ip address changes everytime I connect I used the domain name instead of the ip address. I guess you might be able to use the other domain name since they will both resolve to the same address but the first one seemed more proper.

hope it helps.

tomcruz.net
 
Your syntax is incorrect for any easy future expansion.

What you have right now is:

NameVirtualHost website1.com:80

<VirtualHost website1.com:80>
DocumentRoot &quot;/Volume2m/Websites/website1.com&quot;
ServerName website1.com
ServerAlias ww2.website1.com
</VirtualHost>

<VirtualHost website1.com:80>
DocumentRoot &quot;/Volume2m/Websites/website2.com&quot;
ServerName website2.com
ServerAlias ww2.website2.com
</VirtualHost>


What you SHOULD have is:

NameVirtualHost *

<VirtualHost *>
DocumentRoot &quot;/Volume2m/Websites/website1.com&quot;
ServerName website1.com
ServerAlias ww2.website1.com
</VirtualHost>

<VirtualHost *>
DocumentRoot &quot;/Volume2m/Websites/website2.com&quot;
ServerName website2.com
ServerAlias ww2.website2.com
</VirtualHost>

This makes adding another virtual host as easy as changing your DNS, and adding another 5 lines to the file accordingly. That's it. The way you have it now, it's not that easy.

The entry at the bottom of your configuration file for whatever VirtualHost whatever:443 should be commented out completely...that means comment all uncommented lines with text from the <VirtualHost whatever:443> to the ending </VirtualHost>.

Ideally, all of the Apache configuration should be in the one file httpd.conf.
 
I tried the asterisk argument and I did not get any response from the second domain, just as rrsub saw on his server. I personally dont see how the domain is not preferable to a ip address since the domain will resolve to the address of the server any way and in my case I dont have other than one ip address to attend to anyway.

I will try the asterisk again and I'll bet it works now that I put my two cents in. fate has a way of proving me an idiot somtimes.

tomcruz.net
 
It doesn't hurt to have the ip address defined somewhere. Most people will have it with the &quot;Listen&quot; directive in the main section. For example &quot;Listen 192.168.0.1:80&quot; will bind the server to that ip address on port 80. Now when an http request comes into the server, all it looks for is the domain names for a match. That is why you need a ServerName directive in each vhost. This is how apache knows which VirtualHost to serve. If there is no match, the first one defined is served. The way bwilliam13 has it is the generally excepted way to create a vhost container using name based addressing.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top