Link to home
Start Free TrialLog in
Avatar of rmaranhao
rmaranhao

asked on

Acessing an Apache Virtual Host by IP

I have an Apache server with several virtual hosts configured. I works fine, but I need to migrate this server (Actually my provider has) and I need to test the new server. I can access the new server by it's IP number, but I cannot access all virtual hosts. Is there a way to do it? To type an url that tells apache to take me to an specific virtual host?

Many thanks,
Roberto.

PS.: A proven NO will receive an A.

 
Avatar of andYetAnotherLoginName
andYetAnotherLoginName

if everything working on server (but dns), why don't you put your hosts into "hosts" lookup file on your (client) machine?
ASKER CERTIFIED SOLUTION
Avatar of andYetAnotherLoginName
andYetAnotherLoginName

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rmaranhao

ASKER

I thought about this, but then I'd loose the ability to reach the production site. I want to test th new server, but I need the real site for the moment.
The lines would be like these:

1.2.3.4      Domain1.com
1.2.3.4      Domain2.com
1.2.3.4      Domain3.com
1.2.3.4      Domain4.com
1.2.3.4      Domain5.com
are you saying you would rather messing with server config than just reboot client when necessary?

oh well. you can't do it without reconfiguring server.

an easy way would be to create another VH with DocumentRoot set to span all other VH's DocumentRoot's.
that may be unappropriate bacause (of one) of misc. reasons:
 - security concerns
 - path-to-root-sensitive VH's individual (per-directory) settings
 - there might be no such a folder
...and nope, that shouldn't work, unless you have host in .com tld :(
I think,
1.2.3.4  www.domainX.com
would be your line.
Avatar of periwinkle
Apache server virtualhost configurations are either IP-based (which means that each different site uses a different IP address), or name-based (which means that they all have the same IP address, but the Apache server delivers the proper site based on the domain name in the URL).

If you are trying to use an IP address for the URL, if all of the sites have the same IP address, then Apache will simply deliver the first one that it encounters.  If they all have separate IP addresses, you should be able to see each individual site.

This is supported by the documentation here:

http://httpd.apache.org/docs-2.0/vhosts/details.html

which states (in part):

"When the connection is first made by a client, the IP address to which the client connected is looked up in the internal IP hash table. (...)  If the entry corresponds to a name-based vhost the name list contains one or more vhost structures. This list contains the vhosts in the same order as the VirtualHost  directives appear in the config file. "

"The first vhost on this list (the first vhost in the config file with the specified IP address) has the highest priority and catches any request to an unknown server name or a request without a Host: header field."

(...)

"If no matching vhost could be found the request is served from the first vhost with a matching port number that is on the list for the IP to which the client connected (as already mentioned before)."

Additionally, lower down in the observations:

"The order of name-/IP-based, the _default_  vhost and the NameVirtualHost directive within the config file is not important. Only the ordering of name-based vhosts for a specific address set is significant. The one name-based vhosts that comes first in the configuration file has the highest priority for its corresponding address set."

and

"If two IP-based vhosts have an address in common, the vhost appearing first in the config file is always matched. Such a thing might happen inadvertently. The server will give a warning in the error logfile when it detects this."

both reiterate the fact that if the IP address cannot be resolved to a single virtualhost, the first one will win.

....

As to a solution for testing, I would recommend setting up subdomains for your sites, such as new.domain.com that use the new ip address (while www.domain.com points to the old one), and modify your httpd.conf on the new server to use that address for testing purposes.



So I guess it's a no...

I appreciate de suggestion.. Will try it out.


But I will still be in trouble when migration times come....

Because I won't be able to redirect the traffic that reaches the old site once I start using my REAL httpd.conf file.

Do you have any suggestions concerning that?
What I really wanted was a server that would accept all these requests:

www.domain1.com
www.domain2.com
IPADDRESS/SOMETHING/DOMAIN1
IPADDRESS/SOMETHING/DOMAIN2

This way I can test and migrate very easily.



ogh... I thought you have virtual hosts already set up.
I'm starting to think that I am more messed up that I thought I was....


The first two already work:
www.domain1.com
www.domain2.com
(Isn't this virtual hosting?)

But I want these to take me to domain 1 and 2 respectively:
SERVERIPADDRESS/SOMETHING/DOMAIN1
SERVERIPADDRESS/SOMETHING/DOMAIN2

Hope it's clearer,
Roberto.
that brings us to what I have suggested before, right? creating another virtualhost, default for http://SERVERIPADDRESS/* requests.

if you don't want to open common parent, yet another way would be create this new host in an empty new dir, and than use mod_rewrite to reach other hosts on this server.
I really do like the suggestion of setting up your local computer's hosts file to point to the new server - you just have to remove those entries, and then you'll be back to the old server.

I agree that mod_rewrite might be another approach, and with andYetAnotherLoginName's suggest of setting up the default setup.