Forum Moderators: phranque
We have a range of IP addresses on our Apache server in different Class C IP blocks that we would like to use with name based hosting. There are many more sites than IP addresses.
Can we configure httpd.conf to use any specific IP address, e.g. three servers:
111.222.333.4
111.222.334.5
111.222.335.6
Obviously the DNS entries would refect the IP addresses.
Thanks.
NameVirtualHost *:80 <VirualHost *:80> ServerName www.mysite.com And you can see the documentation for this all at [httpd.apache.org ] and some examples at [httpd.apache.org ]
As always, you can pretty much do anything you could ever want with Apache :-)
Thanks very much.
I updated httpd.conf from the current fixed, shared IP address to:
NameVirtualHost *:80
And all of the sites on the server stopped working. I restored it to the original IP address and it everything was OK again.
Any idea why that wouldn't work?
Would it work if we had multiple "NameVirtualHost" statements, one for each shared IP address?
Is there any other way of having multiple shared IP addresses instead of the existing single fixed shared IP address?
Thanks again and regards.
Having multiple NameVirtualHosts in the main server config will not work -- only the last one will be used, which is probably not what you expect. It might be possible to specify a more specific pattern of IP addresses (perhaps 111.222.333.*:80 might work -- I don't know), but it kind of misses the point of name-based virtual hosts.
The way I think about this is:
NameVirtualHost *:80 tells Apache that you want to consider any traffic comes in on any IP address via post 80 as a possible virtual host (and that you want to use vhosts).
<VirtualHost *:80> tells Apache that this is a possible match for the request. You'll have one of these for each distinct server.
ServerName, which you should define within the <VirtualHost> section, tells Apache to look in the incoming request for the actual DNS name to determine if this is the correct virtual host to use for the request. Make sure that a server with this name is is NOT specified in a ServerName directive in the main server configuration.
Here's an example for a site serving www.site1.com and www.site2.com over port 80 in httpd.conf:
NameVirtualHost *:80<VirtualHost *:80>
ServerName www.site1.com
... other directives, notably DocumentRoot, log files, etc.
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
... other directives that are different than site1 for this site
</VirtualHost>
Here's another link from the Apache doc that describes how matching is done: [httpd.apache.org ].
Thanks very much for the information.
I didn't alter all of the sites to "<VirtualHost *:80>" because there are 350 sites on the server, and I do not want to do anything more drastic than is really necessary.
The reason I thought that multiple "NameVirtualHost" statements would work is because of one of the examples given by apache. This example is based on a private network and a public network, but the principle is the same. This is what the page states:
______________________________________
"The server machine has two IP addresses (192.168.1.1 and 172.20.30.40). The machine is sitting between an internal (intranet) network and an external (internet) network. Outside of the network, the name server.example.com resolves to the external address (172.20.30.40), but inside the network, that same name resolves to the internal address (192.168.1.1
The server can be made to respond to internal and external requests with the same content, with just one VirtualHost section.
Server configuration
NameVirtualHost 192.168.1.1
NameVirtualHost 172.20.30.40
<VirtualHost 192.168.1.1 172.20.30.40>
DocumentRoot /www/server1
ServerName server.example.com
ServerAlias server
</VirtualHost>
___________________________
This example leads me to think that it might be possible to declare any number of NameVirtualHosts and allocate a virtual host to any site?
Thanks again. Best regards.
But the VirtualHost's still need to match the IP pattern you define in NameVirtualHost. I'm not sure exactly what the mechanism is, but to use name-based vhosts, the final matching is done not by IP address, but by the domain name passed in the request compared to the ServerName directive within the VirtualHost.
If you are trying to move from IP to name based matching, you're going to need to change all of your VirtualHost sections ... I think :-)
Thanks again.
Actually we were using name based before, but on a single IP address. What we want to do now is use a wider range of IP addresses but it will still be name based because as I said before that server has over 350 sites hosted already.
Having thought about it further, it seems to me that logically what we are doing is using "NameVirtualHost" to declare the IP adresses that will host virtual sites, and then the "VirtualHost 123.456.789.123" specifies which of the named IP addresses a particular site is virtually hosted on.
Thanks again and best regards.