NameVirtualHost directive warning for Localhost - apache

I have read through many posts and have configured WAMP for 2 sites on the same IP address as follows (httpd.conf extract):
#Tell Apache to identify which site by name
NameVirtualHost *:80
#Tell Apache to serve the default WAMP server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>
#Tell Apache configuration for 1 site
<VirtualHost 127.0.0.1>
ServerName client1.localhost
DocumentRoot "C:/wamp/www_client1"
<Directory "C:/wamp/www_client1">
allow from all
order allow,deny
AllowOverride all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
#Tell Apache configuration for 2 site
<VirtualHost 127.0.0.1>
ServerName client2.localhost
DocumentRoot "C:/wamp/www_client2"
<Directory "C:/wamp/www_client2">
allow from all
order allow,deny
AllowOverride all
</Directory>
I have also changed the Windows hosts file to add 127.0.0.1 client1.localhost etc. however when I restart the WAMP services, //client1.localhost and //client2.localhost go to the default site in the c:\wamp\www folder.
Any help really appreciated.

Have you included your vhosts.conf in your httpd.conf?
Uncomment this line (the one that starts with 'Include') near the bottom of httpd.conf:
# Virtual hosts - leave this commented
Include conf/extra/httpd-vhosts.conf
Edit:
It looks like the problem is that NameVirtualHost and VirtualHost have to match, so you can't have NameVirtualHost *:80 and VirtualHost 127.0.0.1. Instead, use NameVirtualHost *:80 and VirtualHost *:80 or NameVirtualHost 127.0.0.1:80 and VirtualHost 127.0.0.1.
If they don't match, you will see the behavior mentioned in your comment where either the virtual host that doesn't match the others will get hit, or if they are all the same, the first on (your default localhost) will get hit.
See this post for more: Wamp Server: Multiple Virtual Hosts are not working on Windows

Try this configuration, its just a few minor mods to yours
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
## must be first so the the wamp menu page loads
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
#Tell Apache configuration for 1 site
<VirtualHost *:80>
ServerName client1.localhost
DocumentRoot "C:/wamp/www_client1"
<Directory "C:/wamp/www_client1">
AllowOverride All
order Allow,Deny
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
#Tell Apache configuration for 2 site
<VirtualHost *:80>
ServerName client2.localhost
DocumentRoot "C:/wamp/www_client2"
<Directory "C:/wamp/www_client2">
AllowOverride All
order Allow,Deny
Allow from all
</Directory>

Related

Xammp Virtualhost Always Redirecting To htdocs

Been stuck on this one for a little while now. Always get redirected to the index of htdocs.
I've ensured NameVirtualHost is un-commented.
Include conf/extra/httpd-vhosts.conf is un-commented.
I've tried changing the directives under the directory from;
Order allow, deny
Allow from all
To
Require all granted
I've restarted Apache multiple times, flushed DNS.
My files currently look like below;
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/development"
ServerName testsite.dev
ServerAlias www.testsite.dev
<Directory "C:/xampp/htdocs/development">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
hosts
127.0.0.1 localhost
127.0.0.1 www.testsite.dev
Am I missing something? Any help would be greatly appreciated!

URL wont direct correctly

I have a problem with my vhost names. I am setuping a vhost in CentOS based OS. In the host file I added 2 vhost URL. And I also edit the httpd.conf file. I added the vhost directory. I restarted the httpd and I opened the URL in the browser. But it doesn't go to my page. It redirect to other page. Asking for hostnames. Here's my setup.
In my httpd.conf I have this:
<VirtualHost *:80>
DocumentRoot /data/APACHE/html/metro
ServerName store6.giftregistry.com.ph
ServerAlias store6.giftregistry.com.ph
<Directory "/data/APACHE/html/metro">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /data/APACHE/html/metro
ServerName store7.giftregistry.com.ph
ServerAlias store7.giftregistry.com.ph
<Directory "/data/APACHE/html/metro">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
In the hosts file I have this:
10.128.0.63 store6.giftregistry.com.ph
10.128.0.63 store7.giftregistry.com.ph
Is there a mistake with my code?
add
NameVirtualHost *:80
on top..
documentation :
http://httpd.apache.org/docs/2.2/vhosts/name-based.html

localhost redirecting to path specified for sub domain

In cakephp, I want to redirect localhost to app2 and client1.localhost to app1.
Instead both are redirecting to app1.
my httpd-vhost is defined as:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "D:\wamp\www\cakephp\app2\webroot\
ServerName localhost
</VirtualHost>
<VirtualHost www.myhost>
DocumentRoot "D:\wamp\app1\webroot"
ServerName client1.localhost
ServerAlias client1.localhost
<Directory "D:\wamp\app1\webroot">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
At first glance there are a few weird things with your vhost config:
The first document root has no closing "
the virtualhost names should both be the same
your referring to the webroot, instead of the approot (there's also a .htacces in your approot)
I use CakePHP 2.x with wamp server with a configuration like this:
make sure the vhost file is uncommented in your apache configuration:
wamp/bin/apache/Apache[version]/conf/httpd.conf (or left click wamp->apache->httpd.conf)
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Try this in wamp/bin/apache/Apache[version]/conf/extra/httpd-vhosts.conf
#
# Use name-based virtual hosting.
#
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>
ServerName client1.localhost
DocumentRoot "D:\wamp\app1"
<Directory "D:\wamp\app1">
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
<VirtualHost *:80>
ServerName dev.localhost
DocumentRoot "D:\wamp\www\cakephp\app2"
<Directory "D:\wamp\www\cakephp\app2">
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
and put this in your hosts file (C:\windows\system32\drivers\etc)
127.0.0.1 localhost
127.0.0.1 dev.localhost
127.0.0.1 client1.localhost
Do a wamp restart all services.
App2 will be available on both localhost and dev.localhost

Windows 7 - XAMPP: vhost keeps redirecting

My hosts file. (Win 7 ultimate)
127.0.0.1 localhost
127.0.0.1 efmm.local
My httpd-vhosts.conf (XAMPP 1.7.3)
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost efmm.local>
DocumentRoot "C:\xampp\htdocs\EFMM"
ServerName efmm.local
ErrorLog "logs/efmm.localhost-error.log"
CustomLog "logs/efmm.localhost-access.log" combined
<Directory "C:\xampp\htdocs\EFMM">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Problem
When I go to efmm.local , the browser redirects to localhost/EFMM.
I also tried <VirtualHost 127.0.0.1:80> instead of <VirtualHost efmm.local>, same result.
Here's how I do it on XP (don't expect it to make any difference in 7)
First, add the virtual host's domain to your HOST (as you did)
I don't put the virtual host webroot under the main htdocs directory. I create a specific webroot next to it, which gives me the following tree:
C:\XAMPP\htdocs
C:\XAMPP\htdocs-seconddomain
C:\XAMPP\htdocs-thirddomain
etc..
So in your case, I would create c:\XAMPP\htdocs-efmm alongside C:\XAMPP\htdocs
Then:
Edit XAMPP's httpd.conf, add and define any Apache options for the new document root, i.e.:
<Directory "C:/XAMPP/htdocs-efmm">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
[any extra apache module instructions you may require]
Order allow,deny
Allow from all
</Directory>
Edit XAMPP's httpd-vhosts.conf, adding the virtual host:
<VirtualHost *:80>
ServerName efmm.local
ServerAlias www.efmm.local
DocumentRoot "C:/XAMPP/htdocs-efmm"
ErrorLog "C:/XAMPP/htdocs-efmm/error.log"
DirectoryIndex index.php index.html index.htm
</VirtualHost>
Restart XAMPP. You may browse your new virtual host now.

Having trouble with multiple hosts on Apache Snow Leopard

I am running Apache on my Mac OS X (Snow Leopard) machine. I want to be able to set up multiple hostnames so that I can develop and test multiple sites at the same time, but I can't seem to get this to work.
Here's what I've tried:
In my etc/hosts file I've set added these entries:
127.0.0.1 testsite1.localdev.com
127.0.0.1 testsite2.localdev.com
Then, in apache2/httpd.conf I have added these entries:
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/www/development/testsite1
ServerName testsite1.localdev.com
<Directory "/Library/WebServer/Documents/www/development/testsite1">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/www/development/testsite2
ServerName testsite2.localdev.com
<Directory "/Library/WebServer/Documents/www/development/testsite2">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
But happens is that both hostnames resolve to the first one listed in the httpd.conf file -- in this case, testsite1. If I switch their positions, then they both resolve to testsite2.
I've also tried changing the area that reads *:80 and replacing that with the specific hostnames for each site, but that has no effect.
I am being sure to reboot apache after each change.
Thanks for any help!
Gary
in /etc/apache2/httpd.conf uncomment the vhost file like:
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
in /private/etc/apache2/extra/httpd-vhosts.conf use...
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
# local test site
<VirtualHost *:80>
<Directory /Users/<youruser>/Sites/test>
AllowOverride All
</Directory>
DocumentRoot "/Users/<youruser>/Sites/test"
ServerName test.local
</VirtualHost>
Be sure that your and Sites folders have permissions of 755
and be sure that you add to your /etc/hosts file...
# test
127.0.0.1 test.local