Solved

Acessing an Apache Virtual Host by IP

Posted on 2004-10-22
252 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
Question by:rmaranhao
    14 Comments
     
    LVL 3

    Expert Comment

    by:andYetAnotherLoginName
    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:
    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
    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
     
    LVL 5

    Author Comment

    by:rmaranhao
    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
    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
    ...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
    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
    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
    mod_rewrite
    0
     
    LVL 5

    Author Comment

    by:rmaranhao
    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
    ogh... I thought you have virtual hosts already set up.
    0
     
    LVL 5

    Author Comment

    by:rmaranhao
    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
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
    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…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles al…
    This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now