VirtualServer DocumentRoot definition fails for only 1 entry

Problems with the Windows version of XAMPP, questions, comments, and anything related.

VirtualServer DocumentRoot definition fails for only 1 entry

Postby someguy » 03. October 2008 02:32

Here is my current setup...

In c:/WINDOWS/system32/drivers/etc/hosts:
Code: Select all
  127.0.0.1  localhost
  127.0.0.1  local.site1.com
  127.0.0.1  local.site2.com
  127.0.0.1  local.site3.com


In c:/localhost/apache/conf/httpd-conf:
Code: Select all
  Include conf/extra/httpd-vhosts.conf


In c:/localhost/apache/conf/extra/httpd-vhosts.conf:
Code: Select all
  NameVirtualHost *:80

  <VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost
    ServerAdmin admin@localhost
    DocumentRoot 'c:/localhost/htdocs'
  </VirtualHost>

  <VirtualHost *:80>
    ServerName local.site1.com
    ServerAlias site1
    ServerAdmin admin@site1
    DocumentRoot c:/localhost/htdocs/private/site1
  </VirtualHost>

  <VirtualHost *:80>
    ServerName local.site2.com
    ServerAlias site2
    ServerAdmin admin@site2
    DocumentRoot c:/localhost/htdocs/private/site2
  </VirtualHost>

  <VirtualHost *:80>
    ServerName local.site3.com
    ServerAlias site3
    ServerAdmin admin@site3
    DocumentRoot c:/localhost/htdocs/private/site3
  </VirtualHost>


http://localhost/ redirects to http://localhost/xampp/

I've left all the original files in the htdocs directory so this is expected and desirable.

http://localhost/private/ displays the standard index showing files and directories

This is also as expected and desirable. I can make this my default home page and select projects easily.

http://localhost/private/site1/ diplays the index.php at that address. Same for site2 and site3.

So far so good.

The Problem:

Any reference to '/' is interpreted as c:/localhost/htdocs/ instead of c:/localhost/htdocs/private/site1/

This ONLY happens in site1! The other two work perfectly.

There is an easy workaround... just put a dummy definition in httpd-conf where site1 is.

But it's driving me crazy. Why doesn't site1 work?
someguy
 
Posts: 7
Joined: 02. October 2008 18:43

Postby someguy » 03. October 2008 03:57

After posting the previous message, I logged off for dinner. An hour later I turned the computer back on and now all three fail. Nothing was changed so apparently my test earlier was flawed. Maybe I forgot to clear the browser cache or something. I'm not sure.

Now all three sites have the default DocumentRoot not the one defined in VirtualHost. Every example I can find says that this is the correct setup.

What am I missing? Someone please help me out here :(
someguy
 
Posts: 7
Joined: 02. October 2008 18:43

Postby Sharley » 03. October 2008 05:24

If there is anything wrong with your vhost configuration it will usually load the first in the list that is the default and will ignore the rest.

Run this command apache -S from a command prompt in the .\xampp\apache\bin folder and see what might be the issues.

Try this first (no entries of any kind before the first IP based container):
Code: Select all
  <VirtualHost 127.0.0.1:80>
    ServerName localhost
    ServerAlias localhost
    ServerAdmin admin@localhost
    DocumentRoot "c:/localhost/htdocs"
  </VirtualHost>

   NameVirtualHost *:80

 <VirtualHost *:80>
    ServerName local.site1.com
    ServerAlias site1
    ServerAdmin admin@site1
    DocumentRoot "c:/localhost/htdocs/private/site1"
  </VirtualHost>

  <VirtualHost *:80>
    ServerName local.site2.com
    ServerAlias site2
    ServerAdmin admin@site2
    DocumentRoot "c:/localhost/htdocs/private/site2"
  </VirtualHost>

  <VirtualHost *:80>
    ServerName local.site3.com
    ServerAlias site3
    ServerAdmin admin@site3
    DocumentRoot "c:/localhost/htdocs/private/site3"
  </VirtualHost>

The first entry is an IP based virtual host followed by your name based vhosts.

Just wrapping the DocumentRoot folders in quotation marks might do the trick also.

Make sure the IPV6 entry is not included in your Windows Hosts file (if you don't use IPV6 that is):
::1 localhost

Good luck.
Sharl
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Postby someguy » 03. October 2008 17:12

Thanks for the response!

I changed my http-vhosts.conf to what you suggested. Same result. It's like the DocumentRoot statements just don't exist. I'm thinking that there must be something in another file that needs to be set to enable these. There is an 'Include conf/extra/httpd-vhosts.conf' in httpd.conf. I can't think what else there would be.

I'm using the newest xampp for windows on a notebook running XP.


apache -S:
Code: Select all
c:\localhost\apache\bin> apache -S

VirtualHost configuration:
127.0.0.1:80           localhost (C:/localhost/apache/conf/extra/httpd-vhosts.conf:1)
wildcard NameVirtualHosts and _default_ servers:
_default_:443          localhost (C:/localhost/apache/conf/extra/httpd-ssl.conf:74)
*:80                   is a NameVirtualHost
         default server local.site1.com (C:/localhost/apache/conf/extra/httpd-vhosts.conf:10)
         port 80 namevhost local.site1.com (C:/localhosts/apache/conf/extra/httpd-vhosts.conf:10)
         port 80 namevhost local.site2.com (C:/localhosts/apache/conf/extra/httpd-vhosts.conf:17)
         port 80 namevhost local.site3.com (C:/localhosts/apache/conf/extra/httpd-vhosts.conf:24)
Syntax OK


I'm not using SSL and have not changed anything in httpd-ssl.conf. Until now, I didn't realize there was a vhost definition in there.

httpd-ssl.conf:
Code: Select all
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache         dbm:logs/ssl.scache
SSLSessionCacheTimeout  300
SSLMutex  default

<VirtualHost _default_:443>
    DocumentRoot "C:/localhost/htdocs"
    ServerName localhost:443
    ServerAdmin admin@localhost

    ErrorLog logs/error.log
    <IfModule log_config_module>
        CustomLog logs/access.log combined
    </IfModule>
    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile conf/ssl.crt/server.crt
    SSLCertificateKeyFile conf/ssl.key/server.key
    <Location />
    </Location>
    <FilesMatch "\.(cgi|shtml|phtml|php|php5|php4|php3)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory "C:/localhost/apache/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>
    <IfModule setenvif_module>
        BrowserMatch ".*MSIE.*" \
                 nokeepalive ssl-unclean-shutdown \
                 downgrade-1.0 force-response-1.0
    </IfModule>
    <IfModule log_config_module>
        CustomLog logs/ssl_request.log \
                  "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    </IfModule>
</VirtualHost>
someguy
 
Posts: 7
Joined: 02. October 2008 18:43

how I got it done

Postby aadpouw » 03. October 2008 21:55

Hi someguy

For a while I've been struggling with a simular problem. (see 'vhost under xampp', about a week ago)
I've been also on a stage that I thought that I had solve it but later found out that I had not solve it.

To the point.
Because of that I had a look at your topic and in the reply of Sharley I saw this '<VirtualHost 127.0.0.1:80>' and tried that out on my situation.
So I got this:

#this one for my regular projects
<VirtualHost 127.0.0.1:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

#this for the tutorial 'zendframework and dojo' from the last webinair...
<VirtualHost 127.0.1.1:80>
DocumentRoot "C:/xampp/var/www/pastebin/public"
ServerName paste.local
ErrorLog mylogs/apache2/paste.local-error_log
CustomLog mylogs/apache2/paste.local-access_log common

<Directory "C:/xampp/var/www/pastebin/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
!! both ip addresses I have defined in my 'hosts' file.


I'm not sure but it might be the solution for your situation too. So if you do this:

<VirtualHost 127.0.0.1:80>
ServerName local.site1.com
ServerAlias site1
ServerAdmin admin@site1
DocumentRoot "c:/localhost/htdocs/private/site1"
</VirtualHost>

<VirtualHost 127.0.1.1:80>
ServerName local.site2.com
ServerAlias site2
ServerAdmin admin@site2
DocumentRoot "c:/localhost/htdocs/private/site2"
</VirtualHost>

<VirtualHost 127.0.2.1:80>
ServerName local.site3.com
ServerAlias site3
ServerAdmin admin@site3
DocumentRoot "c:/localhost/htdocs/private/site3"
</VirtualHost>

Who knows?
Goodluck
aadpouw
 
Posts: 8
Joined: 14. September 2008 08:29

Postby someguy » 03. October 2008 22:18

OMG !

That seems to have fixed it!

Thank you! And congratulations on getting yours working too.

And thank you Sharley for getting us on the right track!

I'll have to do some more thorough testing but a superficial check looks like we have a winner.

<Does a happy dance>
someguy
 
Posts: 7
Joined: 02. October 2008 18:43

Postby someguy » 03. October 2008 22:50

Once I switched things out to work with my actual website folders instead of the test folders, things were back to failing. :(

However, this time when I checked the error logs something registered that I had been missing. I noticed that the IP for the error was 127.0.0.1 when I was in a virtual host assigned to 127.0.0.2. That made me think 'well, how is it supposed to know which virtual host I want?'.

Then it hit me...

I am a very stupid man sometimes!

My directory structure is:

c:/localhost/htdocs/private/site1
c:/localhost/htdocs/private/site2
c:/localhost/htdocs/private/site3

I was starting my browser with a default home page of http://localhost/private which showed an index of the private directory. This showed:

site1
site2
site3

I was clicking on those links. THAT WON"T WORK!!!!!

I was IN 127.0.0.1 and LOOKING at the files in the other virtual hosts. I wasn't IN the other virtual hosts.

I went to my browser and typed in http://127.0.0.2 and everything works perfectly.

You may all laugh at me now! I can't believe I am so dense sometimes.

Thank you everyone who tried to help. Hopefully my blunder will help point someone else toward an answer when they start playing with virtual hosts.
someguy
 
Posts: 7
Joined: 02. October 2008 18:43

no worries

Postby aadpouw » 04. October 2008 09:52

From mistakes we learn the most.
And yes, sometimes it is looking for that needle in the haystaple :lol:
aadpouw
 
Posts: 8
Joined: 14. September 2008 08:29


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 58 guests