Virtual hosts

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

Virtual hosts

Postby tpothen » 21. August 2008 13:33

I am adding a 2nd site to my server and cannot get virtual host to work correctly. My main site works fine http://www.canoemn.com but the second site does not work http://www.crowwingriver.com. When I type http://crowwingriver.com on the server the site works, when I type http://www.crowwingriver.com it does not.

I have virtual hosts enabled in the http.conf
Code: Select all
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

here is the httpd-vhosts
Code: Select all
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host.example.com
##    DocumentRoot /www/docs/dummy-host.example.com
##    ServerName dummy-host.example.com
##    ServerAlias www.dummy-host.example.com
##    ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
##    CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
##</VirtualHost>

##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host2.example.com
##    DocumentRoot /www/docs/dummy-host2.example.com
##    ServerName dummy-host2.example.com
##    ErrorLog @rel_logfiledir@/dummy-host2.example.com-error_log
##    CustomLog @rel_logfiledir@/dummy-host2.example.com-access_log common
##</VirtualHost>
NameVirtualHost *
<VirtualHost *:80>
    DocumentRoot "C:/webserver/htdocs/canoemn.com"
    ServerName canoemn.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/webserver/htdocs/crowwingriver.com"
    ServerName crowwingriver.com
</VirtualHost>

and here is the hosts file
Code: Select all
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       phpmyadmin
127.0.0.1   crowwingriver.com
127.0.0.1   canoemn.com


Does anyone see why site 2 is not working?
Thanks
tpothen
 
Posts: 5
Joined: 21. August 2008 13:22

Postby w4vy » 21. August 2008 13:48

Yes you haven't wrote out your virtual host.conf file correctly

It needs to look like is shows you here look :-

##<VirtualHost *:80>
## ServerAdmin webmaster@dummy-host2.example.com
## DocumentRoot /www/docs/dummy-host2.example.com
## ServerName dummy-host2.example.com
## ServerAlias www.dummy-host.example.com
## ErrorLog @rel_logfiledir@/dummy-host2.example.com-error_log
## CustomLog @rel_logfiledir@/dummy-host2.example.com-access_log common
##</VirtualHost>

and not like you have it here :-

<VirtualHost *:80>
DocumentRoot "C:/webserver/htdocs/canoemn.com"
ServerName canoemn.com
</VirtualHost>

You see hgow much you have missed out.

w4vy
Image
User avatar
w4vy
 
Posts: 153
Joined: 04. June 2008 09:58
Location: England

Postby glitzi85 » 21. August 2008 17:57

@tpothen:
Ignore the post from w4vy, it is absolutely wrong. You just have to remove this Line:

Code: Select all
NameVirtualHost *


from your File, the NameVirtualHost-Directive is already defined correct in the first line of the file.

The most important rule for VirtualHosts is to use the same format in NameVirtualHost as in the VirtualHosts-Block.

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Postby tpothen » 21. August 2008 18:30

glitzi85, I removed
Code: Select all
NameVirtualHost *

Now http://www.crowwingriver.com brings up http://www.canoemn.com instead of the correct index.html in the crowwingriver.com directory.
I do not believe I need all the other info from w4vy's post. Any more ideas?

Thanks for the help.
tpothen
 
Posts: 5
Joined: 21. August 2008 13:22

Postby glitzi85 » 21. August 2008 19:16

www.example.com is NOT the same as example.com

If you want to use www-Subdomain you have to declare them both in hosts-file as in your Apache configuration file.

Example:

hosts:
Code: Select all
127.0.0.1     example.com
127.0.0.1     www.example.com
127.0.0.1     example.org
127.0.0.1     www.example.org

vHosts-file:
Code: Select all
NameVirtualHosts *:80

<VirtualHost *:80>
   DocumentRoot /webserver/htdocs/example.com
   ServerName example.com
   ServerAlias www.example.com
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot /webserver/htdocs/example.org
   ServerNaem example.org
   ServerAlias www.example.org
</VirtualHost>

# The following Block is only necessary if the folder is outside the
# folder declared in the <Directory>-Block inside the httpd.conf

<Directory "C:/webserver/htdocs">
   Order allow,deny
   allow from all
</Directory>


Also you have to restart your Apache after changing the configuration and very important: Clear your Browser Cache!

The Directories used in the configuration file MUST exist BEFORE you start the Webserver!

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

http://yourdomain.com vs. http://www.yourdomain.com

Postby twbeebe » 22. August 2008 09:09

I found this little tibid of advice in one of the Free Modules offered through ZenCart.com. This may help, or it may not ? When I run multiple sites off of one hosting package, each new domain, is a folder off of the master /htdocs. Then I point the DNS to that folder and all works properly as if, each were on their own seperate hosting package. All are on Apache Servers and I did nothing special in the configurations to make each folder work, inclusive of their www identity ?

## Add these to your .htaccess file so that only one way to your site exists, either http://yoursite.com and http://www.yoursite.com ... the following adds the www if it's missing:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]

## If you'd like your site to go to http://mysite.com instead of http://www.mysite.com, add these changes instead:

##RewriteEngine On
##RewriteCond %{HTTP_HOST} ^www.yoursite.com$ [NC]
##RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]

## the following makes sure the correct mime type is sent for the .htc file
AddType text/x-component .htc
twbeebe
 
Posts: 5
Joined: 25. May 2008 17:31
Location: Penryn, CA

Re: http://yourdomain.com vs. http://www.yourdomain.com

Postby glitzi85 » 22. August 2008 11:50

twbeebe wrote:Then I point the DNS to that folder and all works properly

It is not possible to point with DNS to an folder! DNS just resolves URLs into IP Addresses. Everything else has to be configured in the Webserver! There is no other way!

If you are talking about a web interface from your hosting provider, then this is normally a combination of DNS and webserver configuration!

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Postby Nobbie » 22. August 2008 13:02

glitzi85 wrote:@tpothen:
Ignore the post from w4vy, it is absolutely wrong.


Sorry, but thats still wrong.

w4vy was right, because the Virtual Host Definitions of tpothen are missing the ServerAlias-Directive, what causes the problems.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Postby w4vy » 22. August 2008 13:29

Nobbie wrote:
glitzi85 wrote:@tpothen:
Ignore the post from w4vy, it is absolutely wrong.


Sorry, but thats still wrong.

w4vy was right, because the Virtual Host Definitions of tpothen are missing the ServerAlias-Directive, what causes the problems.


Thanks you so much Nobbie I knew I was right I just read what glitzi said that I was ABSOLUTLY WRONG and was like WTF! Anyway I hope tpohen has fixed the problem now and I think glitzi should do some research before slagging off someone elses comments as false.

Regards, w4vy

EDIT: ALSO IGNORE what that other guy said about using htaccess files because once you have set up your server config correctly you don't need to use htaccess files for what you want to do and that would just cause more server overhead that you don't need.
Image
User avatar
w4vy
 
Posts: 153
Joined: 04. June 2008 09:58
Location: England

Postby glitzi85 » 22. August 2008 13:58

Nobbie wrote:
glitzi85 wrote:@tpothen:
Ignore the post from w4vy, it is absolutely wrong.


Sorry, but thats still wrong.

w4vy was right, because the Virtual Host Definitions of tpothen are missing the ServerAlias-Directive, what causes the problems.

Argh... Note to myself: Read posts more carefully! Was not recognizing that he also wanted a www-Alias in his initial post. Sorry for that.

But in fact he do not need ALL the Settings from the example-Configuration.

Regarding the .htaccess solution: This wont work correct unless you specified the ServerAlias directive. It would be just a additional optical solution that users typing the domain would be redirected to the www alias, in fact that is in most cases not necessary.

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Postby w4vy » 22. August 2008 14:00

glitzi85 wrote:Argh... Note to myself: Read posts more carefully!

glitzi


:D
Image
User avatar
w4vy
 
Posts: 153
Joined: 04. June 2008 09:58
Location: England

Postby tpothen » 22. August 2008 15:16

Thanks everyone for the help. I do have it working for the most part. When I type www.crowwingriver.com it goes the the correct site but if I type crowwingriver.com it goes to www.canoemn.com.
tpothen
 
Posts: 5
Joined: 21. August 2008 13:22

Postby w4vy » 22. August 2008 15:34

pla show me your virtual.conf file
Image
User avatar
w4vy
 
Posts: 153
Joined: 04. June 2008 09:58
Location: England

Postby tpothen » 22. August 2008 15:40

Heres the file.
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "C:/webserver/htdocs/canoemn.com"
    ServerName www.canoemn.com
    ServerAlias www.canoemn.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/webserver/htdocs/canoemn.com"
    ServerName canoemn.com
    ServerAlias canoemn.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/webserver/htdocs/crowwingriver.com"
    ServerName www.crowwingriver.com
    ServerAlias www.crowwingriver.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/webserver/htdocs/crowwingriver.com"
    ServerName crowwingriver.com
    ServerAlias crowwingriver.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/webserver/phpmyadmin"
    ServerName phpmyadmin
</VirtualHost>
tpothen
 
Posts: 5
Joined: 21. August 2008 13:22

Postby w4vy » 22. August 2008 15:55

<VirtualHost *:80>
DocumentRoot "C:/webserver/htdocs/canoemn.com"
ServerAdmin webmaster@canoemn.com
ServerName canoemn.com
ServerAlias www.canoemn.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:/webserver/htdocs/crowwingriver.com"
ServerAdmin webmaster@crowwingriver.com
ServerName crowwingriver.com
ServerAlias www.crowwingriver.com
</VirtualHost>

Try that k you had 2 for each one which you don't do. also why have you got one set for php myadmin ?
Image
User avatar
w4vy
 
Posts: 153
Joined: 04. June 2008 09:58
Location: England

Next

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 153 guests