Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Acessing an Apache Virtual Host by IP

Posted on 2004-10-22
14
Medium Priority
?
257 Views
Last Modified: 2010-03-04
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.

 
0
Comment
Question by:rmaranhao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 3

Expert Comment

by:andYetAnotherLoginName
ID: 12380483
if everything working on server (but dns), why don't you put your hosts into "hosts" lookup file on your (client) machine?
0
 
LVL 3

Accepted Solution

by:
andYetAnotherLoginName earned 2000 total points
ID: 12380551
I mean, add lines such as

1.2.3.4      host1.domain.com
1.2.3.4      host2.domain.com
1.2.3.4      host3.domain.com

and then just type URLs as usually?
0
 
LVL 5

Author Comment

by:rmaranhao
ID: 12380563
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.
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.

 
LVL 5

Author Comment

by:rmaranhao
ID: 12380595
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
0
 
LVL 3

Expert Comment

by:andYetAnotherLoginName
ID: 12380627
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
0
 
LVL 3

Expert Comment

by:andYetAnotherLoginName
ID: 12380646
...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.
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12380652
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.



0
 
LVL 5

Author Comment

by:rmaranhao
ID: 12380795
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?
0
 
LVL 3

Expert Comment

by:andYetAnotherLoginName
ID: 12380827
mod_rewrite
0
 
LVL 5

Author Comment

by:rmaranhao
ID: 12380835
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.



0
 
LVL 3

Expert Comment

by:andYetAnotherLoginName
ID: 12380851
ogh... I thought you have virtual hosts already set up.
0
 
LVL 5

Author Comment

by:rmaranhao
ID: 12380890
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.
0
 
LVL 3

Expert Comment

by:andYetAnotherLoginName
ID: 12380958
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.
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12381017
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question