httpd.conf - need help with virtual hosts

Discussion in 'NZ Computing' started by a.d., Oct 11, 2005.

  1. a.d.

    a.d. Guest

    Hi

    I've added the <VirtualHost> block like the Apache FAQ says, but it
    doesn't seem to work.

    I am running XAMPP for Windows (Apache, MySQL, PHP, Perl). The Apache
    FAQ says to do 2 things for name-based virtual hosts on a single IP address.

    1) Enable <NameVirtualHost>. Done.
    NameVirtualHost *:80

    2) Add a new <VirtualHost> block for each website I want to host. Done.
    <VirtualHost *:80>
    ServerName sitename1
    DocumentRoot "D:/www/sitename1"
    </VirtualHost>
    <VirtualHost *:80>
    ServerName sitename2
    DocumentRoot "D:/www/sitename2"
    </VirtualHost>

    http://localhost/ works fine, it brings up the default local XAMPP
    website, but if I type http://sitename1/ it runs off and does a Google
    search.

    Can anyone point out what I've done wrong? Am I supposed to disable the
    ServerName and DocumentRoot elements near the top of the httpd.conf file?

    Cheers
     
    a.d., Oct 11, 2005
    #1
    1. Advertising

  2. a.d.

    a.d. Guest

    a.d. wrote:
    > Hi
    >
    > I've added the <VirtualHost> block like the Apache FAQ says, but it
    > doesn't seem to work.
    >
    > I am running XAMPP for Windows (Apache, MySQL, PHP, Perl). The Apache
    > FAQ says to do 2 things for name-based virtual hosts on a single IP
    > address.
    >
    > 1) Enable <NameVirtualHost>. Done.
    > NameVirtualHost *:80
    >
    > 2) Add a new <VirtualHost> block for each website I want to host. Done.
    > <VirtualHost *:80>
    > ServerName sitename1
    > DocumentRoot "D:/www/sitename1"
    > </VirtualHost>
    > <VirtualHost *:80>
    > ServerName sitename2
    > DocumentRoot "D:/www/sitename2"
    > </VirtualHost>
    >
    > http://localhost/ works fine, it brings up the default local XAMPP
    > website, but if I type http://sitename1/ it runs off and does a Google
    > search.
    >
    > Can anyone point out what I've done wrong? Am I supposed to disable the
    > ServerName and DocumentRoot elements near the top of the httpd.conf file?
    >
    > Cheers


    I seem to have fixed this but not in an expected way. There is a file
    called "hosts" (no extension) in the windows directory:
    C:\WINXP\system32\drivers\etc\

    It listed the following:
    127.0.0.1 localhost

    I added the following:
    127.0.0.1 sitename1
    127.0.0.1 sitename2

    .... and now it works. Is this the normal way to get VirtualHosts to work
    with Apache in Windows?
     
    a.d., Oct 11, 2005
    #2
    1. Advertising

  3. a.d.

    Harry Guest

    a.d. wrote:

    > Hi
    >
    > I've added the <VirtualHost> block like the Apache FAQ says, but it
    > doesn't seem to work.
    >
    > I am running XAMPP for Windows (Apache, MySQL, PHP, Perl). The Apache
    > FAQ says to do 2 things for name-based virtual hosts on a single IP
    > address.
    >
    > 1) Enable <NameVirtualHost>. Done.
    > NameVirtualHost *:80
    >
    > 2) Add a new <VirtualHost> block for each website I want to host. Done.
    > <VirtualHost *:80>
    > ServerName sitename1
    > DocumentRoot "D:/www/sitename1"
    > </VirtualHost>
    > <VirtualHost *:80>
    > ServerName sitename2
    > DocumentRoot "D:/www/sitename2"
    > </VirtualHost>
    >
    > http://localhost/ works fine, it brings up the default local XAMPP
    > website, but if I type http://sitename1/ it runs off and does a Google
    > search.
    >
    > Can anyone point out what I've done wrong? Am I supposed to disable the
    > ServerName and DocumentRoot elements near the top of the httpd.conf file?
    >


    The DNS lookup of "sitename1" is going to fail unless you
    are running your own local DNS server with a definition in it.
    Perhaps you should try putting a definition in /windows/hosts file.
    Map it to 127.0.0.1 or to the IP of a particular nic.
     
    Harry, Oct 11, 2005
    #3
  4. a.d.

    Shane Guest

    On Wed, 12 Oct 2005 01:26:56 +1300, a.d. wrote:

    > a.d. wrote:
    >> Hi
    >>
    >> I've added the <VirtualHost> block like the Apache FAQ says, but it
    >> doesn't seem to work.
    >>
    >> I am running XAMPP for Windows (Apache, MySQL, PHP, Perl). The Apache
    >> FAQ says to do 2 things for name-based virtual hosts on a single IP
    >> address.
    >>
    >> 1) Enable <NameVirtualHost>. Done.
    >> NameVirtualHost *:80
    >>
    >> 2) Add a new <VirtualHost> block for each website I want to host. Done.
    >> <VirtualHost *:80>
    >> ServerName sitename1
    >> DocumentRoot "D:/www/sitename1"
    >> </VirtualHost>
    >> <VirtualHost *:80>
    >> ServerName sitename2
    >> DocumentRoot "D:/www/sitename2"
    >> </VirtualHost>
    >>
    >> http://localhost/ works fine, it brings up the default local XAMPP
    >> website, but if I type http://sitename1/ it runs off and does a Google
    >> search.
    >>
    >> Can anyone point out what I've done wrong? Am I supposed to disable the
    >> ServerName and DocumentRoot elements near the top of the httpd.conf file?
    >>
    >> Cheers

    >
    > I seem to have fixed this but not in an expected way. There is a file
    > called "hosts" (no extension) in the windows directory:
    > C:\WINXP\system32\drivers\etc\
    >
    > It listed the following:
    > 127.0.0.1 localhost
    >
    > I added the following:
    > 127.0.0.1 sitename1
    > 127.0.0.1 sitename2
    >
    > ... and now it works. Is this the normal way to get VirtualHosts to work
    > with Apache in Windows?


    nah
    its not apache having troubles.. its your dns

    --
    Hardware, n.: The parts of a computer system that can be kicked

    The best way to get the right answer on usenet is to post the wrong one.
     
    Shane, Oct 11, 2005
    #4
  5. a.d.

    AD. Guest

    On Wed, 12 Oct 2005 01:26:56 +1300, a.d. wrote:

    > I seem to have fixed this but not in an expected way. There is a file
    > called "hosts" (no extension) in the windows directory:
    > C:\WINXP\system32\drivers\etc\
    >
    > It listed the following:
    > 127.0.0.1 localhost
    >
    > I added the following:
    > 127.0.0.1 sitename1
    > 127.0.0.1 sitename2
    >
    > ... and now it works. Is this the normal way to get VirtualHosts to work
    > with Apache in Windows?


    Thats not getting Virtual Hosts to work (they were already working) - the
    hosts thing was so your browser knew where to look for them.

    You would've needed to do the same thing in any other web server.

    --
    Cheers
    Anton
     
    AD., Oct 12, 2005
    #5
  6. a.d.

    Dave Doe Guest

    In article <1129088265.6cffc8bd5910914301a63fdda1bfd2de@teranews>,
    says...
    > On Wed, 12 Oct 2005 01:26:56 +1300, a.d. wrote:
    >
    > > I seem to have fixed this but not in an expected way. There is a file
    > > called "hosts" (no extension) in the windows directory:
    > > C:\WINXP\system32\drivers\etc\
    > >
    > > It listed the following:
    > > 127.0.0.1 localhost
    > >
    > > I added the following:
    > > 127.0.0.1 sitename1
    > > 127.0.0.1 sitename2
    > >
    > > ... and now it works. Is this the normal way to get VirtualHosts to work
    > > with Apache in Windows?

    >
    > Thats not getting Virtual Hosts to work (they were already working) - the
    > hosts thing was so your browser knew where to look for them.
    >
    > You would've needed to do the same thing in any other web server.


    Updating the hosts file is um... 'cheating' :) All you're doing is
    creating *local* (per PC) pointers on that windows box to the site. ie
    it'll only work on that PC, and not any other PC on planet earth, sorry.

    --
    Duncan
     
    Dave Doe, Oct 12, 2005
    #6
  7. a.d.

    Shane Guest

    On Wed, 12 Oct 2005 19:00:07 +1300, Dave Doe wrote:

    > In article <1129088265.6cffc8bd5910914301a63fdda1bfd2de@teranews>,
    > says...
    >> On Wed, 12 Oct 2005 01:26:56 +1300, a.d. wrote:
    >>
    >> > I seem to have fixed this but not in an expected way. There is a file
    >> > called "hosts" (no extension) in the windows directory:
    >> > C:\WINXP\system32\drivers\etc\
    >> >
    >> > It listed the following:
    >> > 127.0.0.1 localhost
    >> >
    >> > I added the following:
    >> > 127.0.0.1 sitename1
    >> > 127.0.0.1 sitename2
    >> >
    >> > ... and now it works. Is this the normal way to get VirtualHosts to work
    >> > with Apache in Windows?

    >>
    >> Thats not getting Virtual Hosts to work (they were already working) - the
    >> hosts thing was so your browser knew where to look for them.
    >>
    >> You would've needed to do the same thing in any other web server.

    >
    > Updating the hosts file is um... 'cheating' :) All you're doing is
    > creating *local* (per PC) pointers on that windows box to the site. ie
    > it'll only work on that PC, and not any other PC on planet earth, sorry.



    At a wild guess Id say the OP was inside a LAN, and the DNS was pointing
    to his external IP, but needed to be pointed at his internal ip
    And thats why he needed to do his hosts file

    --
    Hardware, n.: The parts of a computer system that can be kicked

    The best way to get the right answer on usenet is to post the wrong one.
     
    Shane, Oct 12, 2005
    #7
  8. a.d.

    Enkidu Guest

    a.d. wrote:
    > a.d. wrote:
    >
    >> Hi
    >>
    >> I've added the <VirtualHost> block like the Apache FAQ says, but it
    >> doesn't seem to work.
    >>
    >> I am running XAMPP for Windows (Apache, MySQL, PHP, Perl). The Apache
    >> FAQ says to do 2 things for name-based virtual hosts on a single IP
    >> address.
    >>
    >> 1) Enable <NameVirtualHost>. Done.
    >> NameVirtualHost *:80
    >>
    >> 2) Add a new <VirtualHost> block for each website I want to host. Done.
    >> <VirtualHost *:80>
    >> ServerName sitename1
    >> DocumentRoot "D:/www/sitename1"
    >> </VirtualHost>
    >> <VirtualHost *:80>
    >> ServerName sitename2
    >> DocumentRoot "D:/www/sitename2"
    >> </VirtualHost>
    >>
    >> http://localhost/ works fine, it brings up the default local XAMPP
    >> website, but if I type http://sitename1/ it runs off and does a Google
    >> search.
    >>
    >> Can anyone point out what I've done wrong? Am I supposed to disable
    >> the ServerName and DocumentRoot elements near the top of the
    >> httpd.conf file?
    >>
    >> Cheers

    >
    >
    > I seem to have fixed this but not in an expected way. There is a file
    > called "hosts" (no extension) in the windows directory:
    > C:\WINXP\system32\drivers\etc\
    >
    > It listed the following:
    > 127.0.0.1 localhost
    >
    > I added the following:
    > 127.0.0.1 sitename1
    > 127.0.0.1 sitename2
    >
    > ... and now it works. Is this the normal way to get VirtualHosts to work
    > with Apache in Windows?
    >

    A webserver distinguishes requests for virtual hosts by
    three things, IP address, port, and Host Header Name. A
    client asks for a page by specifying three things (if it is
    HTTP1.1), the IP address, the port and the Host Header Name.

    When you request http://domain1 with your browser, your
    browser first looks up the IP address of 'domain1'. In your
    case the browser is running on the server so your IP address
    is the loopback interface address or 127.0.0.1. Since you
    have put domain name and the IP address in the hosts file,
    the browser can look up 'domain1' and get the correct IP
    addresss, 127.0.0.1.

    Since you use "http" and don't specify a port number the
    default is port 80.

    Since your browser understands HTTP 1.1 it send the Domain
    Name you specified as the "Host Header Name".

    When the server gets the request (which doesn't leave your
    machine!) it has the three bits of information that it needs
    to determine the correct VirtualHost!

    Without the hosts files entries it didn't know that the site
    'domain1' was on the local machine! That's why it went off
    to Google!

    Normally on a Virtual Host machine you would have a number
    of sites each with different names. Each site would have the
    same IP address and would have the same (default) port.

    A remote client would look up the IP address in the usual
    way in DNS and send the request to the default port number
    and the IP address, specifying the Host Header Name in the
    request. The server would then have the three bits of
    information it needs to direct the request to the right
    virtual host.

    Cheers,

    Cliff

    --

    Barzoomian the Martian - http://barzoomian.blogspot.com
     
    Enkidu, Oct 12, 2005
    #8
  9. In message <1129088265.6cffc8bd5910914301a63fdda1bfd2de@teranews>, AD.
    wrote:

    > On Wed, 12 Oct 2005 01:26:56 +1300, a.d. wrote:
    >
    >> I seem to have fixed this but not in an expected way. There is a file
    >> called "hosts" (no extension) in the windows directory:
    >> C:\WINXP\system32\drivers\etc\
    >>
    >> It listed the following:
    >> 127.0.0.1 localhost
    >>
    >> I added the following:
    >> 127.0.0.1 sitename1
    >> 127.0.0.1 sitename2
    >>
    >> ... and now it works. Is this the normal way to get VirtualHosts to work
    >> with Apache in Windows?

    >
    > Thats not getting Virtual Hosts to work (they were already working) - the
    > hosts thing was so your browser knew where to look for them.
    >
    > You would've needed to do the same thing in any other web server.


    By the way, Apache itself is quite good at helping you debug these sorts of
    problems. Just Telnet to port 80 on your Web server, and type in an HTTP
    request by hand, e.g.

    GET / HTTP/1.0
    Host: sitename1


    (Press return twice to add a blank line at the end.) It should then spit
    back the home page for the specified virtual site. Similarly try sitename2,
    and see that you get back what you expect.

    It helps to get things working to this level before going to get your DNS
    configured. That way there's only one thing to go wrong at a time. :)
     
    Lawrence D'Oliveiro, Oct 13, 2005
    #9
  10. a.d.

    Enkidu Guest

    Lawrence D'Oliveiro wrote:
    > In message <1129088265.6cffc8bd5910914301a63fdda1bfd2de@teranews>, AD.
    > wrote:
    >
    >
    >>On Wed, 12 Oct 2005 01:26:56 +1300, a.d. wrote:
    >>
    >>
    >>>I seem to have fixed this but not in an expected way. There is a file
    >>>called "hosts" (no extension) in the windows directory:
    >>>C:\WINXP\system32\drivers\etc\
    >>>
    >>>It listed the following:
    >>>127.0.0.1 localhost
    >>>
    >>>I added the following:
    >>>127.0.0.1 sitename1
    >>>127.0.0.1 sitename2
    >>>
    >>>... and now it works. Is this the normal way to get VirtualHosts to work
    >>>with Apache in Windows?

    >>
    >>Thats not getting Virtual Hosts to work (they were already working) - the
    >>hosts thing was so your browser knew where to look for them.
    >>
    >>You would've needed to do the same thing in any other web server.

    >
    >
    > By the way, Apache itself is quite good at helping you debug these sorts of
    > problems. Just Telnet to port 80 on your Web server, and type in an HTTP
    > request by hand, e.g.
    >
    > GET / HTTP/1.0
    > Host: sitename1
    >
    > (Press return twice to add a blank line at the end.) It should then spit
    > back the home page for the specified virtual site. Similarly try sitename2,
    > and see that you get back what you expect.
    >
    > It helps to get things working to this level before going to get your DNS
    > configured. That way there's only one thing to go wrong at a time. :)


    HEAD / HTTP/1.1
    Host: sitename

    gets you the header info without the other stuff.

    Cheers,

    Cliff

    --

    Barzoomian the Martian - http://barzoomian.blogspot.com
     
    Enkidu, Oct 14, 2005
    #10
  11. In message <434f68ac$>, Enkidu wrote:

    > Lawrence D'Oliveiro wrote:
    >> In message <1129088265.6cffc8bd5910914301a63fdda1bfd2de@teranews>, AD.
    >> wrote:
    >>
    >>
    >>>On Wed, 12 Oct 2005 01:26:56 +1300, a.d. wrote:
    >>>
    >>>
    >>>>I seem to have fixed this but not in an expected way. There is a file
    >>>>called "hosts" (no extension) in the windows directory:
    >>>>C:\WINXP\system32\drivers\etc\
    >>>>
    >>>>It listed the following:
    >>>>127.0.0.1 localhost
    >>>>
    >>>>I added the following:
    >>>>127.0.0.1 sitename1
    >>>>127.0.0.1 sitename2
    >>>>
    >>>>... and now it works. Is this the normal way to get VirtualHosts to work
    >>>>with Apache in Windows?
    >>>
    >>>Thats not getting Virtual Hosts to work (they were already working) - the
    >>>hosts thing was so your browser knew where to look for them.
    >>>
    >>>You would've needed to do the same thing in any other web server.

    >>
    >>
    >> By the way, Apache itself is quite good at helping you debug these sorts
    >> of problems. Just Telnet to port 80 on your Web server, and type in an
    >> HTTP request by hand, e.g.
    >>
    >> GET / HTTP/1.0
    >> Host: sitename1
    >>
    >> (Press return twice to add a blank line at the end.) It should then spit
    >> back the home page for the specified virtual site. Similarly try
    >> sitename2, and see that you get back what you expect.
    >>
    >> It helps to get things working to this level before going to get your DNS
    >> configured. That way there's only one thing to go wrong at a time. :)

    >
    > HEAD / HTTP/1.1
    > Host: sitename
    >
    > gets you the header info without the other stuff.


    That's not usually enough to tell whether you're getting the right page or
    not.
     
    Lawrence D'Oliveiro, Oct 14, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. grzybek

    DNS problem, suspect PIX conf

    grzybek, Jan 29, 2004, in forum: Cisco
    Replies:
    5
    Views:
    2,202
    grzybek
    Feb 2, 2004
  2. Gustav
    Replies:
    1
    Views:
    474
    News Account
    Feb 21, 2004
  3. spec
    Replies:
    7
    Views:
    1,353
    Peter
    Jun 5, 2006
  4. OmOd_Rye

    Help with Cisco 827 conf.

    OmOd_Rye, Aug 22, 2007, in forum: Cisco
    Replies:
    0
    Views:
    2,354
    OmOd_Rye
    Aug 22, 2007
  5. sunilcnair
    Replies:
    1
    Views:
    1,809
    thort
    Oct 1, 2007
Loading...

Share This Page