logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Problem with localhost when virtual hosts are working fine
Author
webprofessor



Joined: 21 Sep 2008
Posts: 4

PostPosted: Sun 21 Sep '08 1:25    Post subject: Problem with localhost when virtual hosts are working fine Reply with quote

Hi I configured two virtual hosts in my XAMPP for windows environment. This is what I did:

1) I edited hosts file and added the following.

127.0.0.1 localhost
127.0.0.1 www.maria.com
127.0.0.1 www.mary.com
::1 localhost


2) I edited httpd-vhosts.conf file and added the following:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.maria.com
DocumentRoot "C:/xampp/htdocs/maria"
DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
</VirtualHost>

<VirtualHost *:80>
ServerName www.mary.com
DocumentRoot "C:/xampp/htdocs/mary"
DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
</VirtualHost>

3) The problem I have is the following:

when I type http://www.mary.com/index.html or http://www.mariah.com/index.html, I see the contents of index.html in browser.

a) If I type http://localhost, I get the error message as follows:

Object not found, Error 404.

I also noticed that the URL changes to http://localhost/xampp.

Before I added virtual hosts, when I type http://localhost, I used to see my index.html displayed in browser.

Did I do something wrong when I configured virtual hosts?

b) Virtual hosts works ok, but I do not understand why I have to type full URL http://www.mary.com/index.html instead of http://www.mary.com.

Did I do something wrong with the set up?

I appreciate your help. I am also adding the part of httpd.conf file which you may be interested to see:

------------ Part of httpd.conf ---------------------
ServerAdmin admin@localhost

ServerName localhost:80

DocumentRoot "C:/xampp/htdocs"

<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>

<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<IfModule dir_module>
DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
</IfModule>
------------------------------------------------------------------------------------

I sincerely appreciate your help.

Thank You.

Srini
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sun 21 Sep '08 2:21    Post subject: Reply with quote

127.0.0.1 localhost
127.0.0.1 www.maria.com
127.0.0.1 www.mary.com
::1 localhost <<-- get rid of this and try again
Back to top
webprofessor



Joined: 21 Sep 2008
Posts: 4

PostPosted: Sun 21 Sep '08 2:56    Post subject: Reply with quote

Thanks for the help. Your suggestion helped me to get closer to my goal.

Still, the problem is not solved.

After removing ::1 localhost from the hosts file, I restarted XAMPP and see what happens.

This time localhost worked, but it is picking up index.html from the first virtual host. I changed the order of virtual hosts to confirm the behavior.

It seems I do have to do one or more changes either in the httpd.conf or httpd-vhosts.conf.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sun 21 Sep '08 3:11    Post subject: Reply with quote

yes .. that is typical .. a typical place where most stumble that is. I saw that it would happen just figured I'd wait and see if the removing the IPv6 call in the host file got you to this point.

between NameVirtualhosts and the first vhost .. what is it ... www.maria.com add this

Code:
<VirtualHost _default_:80>
DocumentRoot C:/xampp/htdocs
</VirtualHost>


This is mentioned, in it's own little box in the docs, but no example is ever shown to make it perfectly clear so it is where many run into trouble.
Back to top
webprofessor



Joined: 21 Sep 2008
Posts: 4

PostPosted: Sun 21 Sep '08 6:35    Post subject: Reply with quote

Great! It works!

I spent almost 24 hours thinking about why localhost and virtual hosts are not working together. Many thanks for your help.

<VirtualHost _default_:80>
DocumentRoot C:/xampp/htdocs
</VirtualHost>

Where did you find the above information? I am curious to know. If it is from a book, I consider buying the book.

What is the meaning of this code? Why is it required?

<VirtualHost _default_:80>
DocumentRoot C:/xampp/htdocs
</VirtualHost>
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sun 21 Sep '08 7:04    Post subject: Reply with quote

Oh man .. that requires me to remember Mr. Green

Honest truth, I've been playing with this beast for 10 years, since sometime mid-June to mid-July of 1998, I have no clue where I first saw this.

I do know, it is in docs ..

http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Quote:
Main host goes away

If you are adding virtual hosts to an existing web server, you must also create a <VirtualHost> block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.


AFAIC there should be example right after this, but there isn't.

Then somewhere completely different in the Docs we find this

http://httpd.apache.org/docs/2.2/vhosts/examples.html (near bottom)
Quote:
Using _default_ vhosts
_default_ vhosts for all ports

Catching every request to any unspecified IP address and port, i.e., an address/port combination that is not used for any other virtual host.
Server configuration

<VirtualHost _default_:*>
DocumentRoot /www/default
</VirtualHost>

Using such a default vhost with a wildcard port effectively prevents any request going to the main server.

A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained an unknown or no Host: header it is always served from the primary name-based vhost (the vhost for that address/port appearing first in the configuration file).


So it is there .. just not easy to find which is why I stated MANY fail here .. you are set up to fail if you follow the manual's examples on the "Name-based" page .. none of them has this shown.

This has uses .. it's a catch-all ... I keep a script there that will either say "The hostname your requested does not exist on the server," or for those adventurers usually up to no good going to my IP directly, they get a black page with big red letters "GO AWAY!"

gregg

EDIT:

Oh yeah, the other issue .. I cannot say for sure on Vista/2008 .. but on XP .. IPv6 and Apache is useless. I also believe that host file is read from top down .. so the IPv6 socket (probably wrong term) was the one bound to localhost .. no the IPv4 which is what your Apache is configured for .. looking at the config you've shown.
Back to top
webprofessor



Joined: 21 Sep 2008
Posts: 4

PostPosted: Sun 21 Sep '08 8:38    Post subject: Reply with quote

Many Thanks for your detailed explanation. I learned a lot today!
Back to top
sos



Joined: 20 Sep 2008
Posts: 6
Location: Bucharest, Romania.

PostPosted: Sun 21 Sep '08 23:45    Post subject: Reply with quote

webprofessor, here is an interesting book if you want to have one at handy. http://oreilly.com/catalog/9780596518882/index.html
Back to top


Reply to topic   Topic: Problem with localhost when virtual hosts are working fine View previous topic :: View next topic
Post new topic   Forum Index -> Apache