Virtual Hosts on WAMP causing 403 forbidden on localhost... other aliases still work - apache

I just realized that nothing else on WAMP is accessible unless it's under the virtual host alias. For example: if I name my vHost 'mysite.dev', I can only access mysite.dev and everything else gives a 403 forbidden error. If I add a vHost called anothersite.dev in addition to mysite.dev, only those sites can be accessed. The only thing under localhost that I can access is PHPMyAdmin. I have uncommented the line that includes vHosts.conf in the Apache httpd.conf file. This problem does not happen until I modify the vHosts.conf file. Here is the config for the other files:
vHosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Windows hosts file:
127.0.0.1 localhost
127.0.0.1 mysite.dev

Ok first, the first 2 VHOST definitions in the httpd-vhost.conf file (vhost and vhost2) are examples, supplied by Apache, to help you get started and of course point to folders that do not exist so and should be removed.
Second When you create a Virtual Host you should include the access privilages for the VHOST in a <Directory....> group.
Third, you should always create a VHOST for localhost as once VHOSTs are created Apache ignores the localhost definition in httpd.conf
So your httpd-vhost.conf file should look like this
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "W:/wamp/www"
ServerName localhost
<Directory "W:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/mysite.dev-error.log"
CustomLog "logs/mysite.dev-access.log" common
<Directory "W:/wamp/www/mysite">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Once you have done this, you now need to edit your c:\windows\system32\drivers\etc\hosts file to look like this. You need to have admin privilages to edit this file, also some anti virus suites also protect this file, so you may need to stop that protection temporarily in order to amend this file.
127.0.0.1 localhost
127.0.0.1 mysite.dev
::1 localhost
::1 mysite.dev
Then restart the dnscache to pick up these changes, from a command line also started with admin privilages.
net stop dnscache
net start dnscache
This post may help you understand more about Virtual Hosts

Related

Add Virtual Host for Localhost Ampps

<VirtualHost *:80>
DocumentRoot "C:/Program Files (x86)/Ampps/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Program Files (x86)/Ampps/www/proj"
ServerName proj.local
</VirtualHost>
How do I bind a specific "domain" (virtual host domain) to one location? Above points proj.local to localhost as well.
As you said you are using AMPPS, I suppose you are adding this instructions to the folder:
AMPPS/apache/conf/extra/httpd-vhosts.conf
With that in mind I'll show an example of configuration.
<VirtualHost project.local:80>
<Directory "/Users/you/yourproject">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName project.local
ServerAlias project.local 127.0.0.1
ScriptAlias /cgi-bin/ "/Users/you/yourproject/cgi-bin/"
DocumentRoot "/Users/you/yourproject"
ErrorLog "/Applications/AMPPS/apache/logs/project.error_log"
CustomLog "/Applications/AMPPS/apache/logs/project.access.log" combined
</VirtualHost>
All right. After doing that, you will have to add to your hosts file. In Mac they are located in:
/etc/hosts
If you are using a Windows environment you will find the hosts file in:
c:\windows\system32\drivers\etc\hosts
Attention: You may have to type your password again or allow the program you're using to edit the file to use administrator privileges.
Then you'll add your local IP and the hostname to it. Just like this:
127.0.0.1 project.local
If you don't add the URL to the hosts file that won't work.
Have you tried with <VirtualHOst proj.local:80>? You should be able to find more examples here: http://httpd.apache.org/docs/2.2/vhosts/examples.html
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\xampp\htdocs"
ServerName xampp.local
ServerAlias www.xampp.local
</VirtualHost>
after adding it at the end of your httpd-vhosts.conf file restart your xampp and also add following lines to your hosts file available at C:\Windows\System32\Drivers\etc\hosts
127.0.0.1 xampp.local

VIrtualHost: Different hosts point to the same location

I am trying to set virtual hosts for two Zend Framework applications. I started by changing the system32 hosts file.
It contains the following lines now:
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 quickstart
After that, I proceeded with changing the httpd-vhosts.conf file. Its current content:
<VirtualHost *:80>
ServerAdmin postmaster#dummy-host2.localhost
DocumentRoot "G:\workspace\Andrew\ProjManer\public"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin postmaster#dummy-host2.localhost
DocumentRoot "G:\workspace\Andrew\quickstart\public"
ServerName quickstart
ServerAlias quickstart
ErrorLog "logs/quickstart-error.log"
CustomLog "logs/quickstart-access.log" combined
</VirtualHost>
If I don't add the virtual host with localhost first, I get a "Access forbidden 403 Error message".
The problem now is that both point to the same location, the localhost. How am I supposed to get the second virtual host working? I used the flushdns also.
You don't need the ServerAlias in them unless you want say quickstart2 to go to quickstart. In that case you will do ServerAlias quickstart2. You get access forbidden because your document root in your httpd.conf doesn't have an index.php or that virtualhost doesn't have an index.php and you have -Indexes set
Other than that the virtualhost and hosts file look fine. Try restarting your browser and restarting apache.

NameVirtualHost causes 404 for localhost

I've managed to setup several VirtualHosts by enabling NameVirtualHost. Here's the top part of my vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.local
...
</VirtualHost>
The problem is when I visit http://localhost I get the default "It works!". If I go to http://127.0.0.1/ it defaults to http://mysite.local
I understand from the Apache Docs that why it defaults to mysite.local (matching the first VirtualHost). But I used to be able to go to http://localhost/phpmyadmin/.
How can I get this back? Do I need to make my first VirtualHost localhost? That seems wrong...
Running apache 2.2.15 on Mac OS X (10.6.6).
UPDATE
If I comment out the following lines from my hosts file, both localhost and 127.0.0.1 go to the same place. I verified in the access log that it was indeed using ::1.
::1 localhost
fe80::1%lo0 localhost
So I suppose that handles the first issue, provided this is okay? But how can I get localhost to go to my default DocumentRoot?
How can I get this back? Do I need to make my first VirtualHost localhost? That seems wrong...
I did it like this and all seems to be working just fine, without needing an extra port to listen on.
The first VirtualHost block
handles any URL that doesn't point to one of the 2 vhosts (2nd and 3rd VirtualHost blocks) I have set up:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/imputation/dirmaster/http/"
ServerName imputation.loc
<Directory "/Applications/XAMPP/xamppfiles/htdocs/imputation/dirmaster/http/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/documentatiebestand/"
ServerName documentatiebestand.loc
<Directory "/Applications/XAMPP/xamppfiles/htdocs/documentatiebestand/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
No, you can't mix VirtualHosts with "classic" configuration.
You could listen on another port and define another VirtualHost (*:8080 for example) "emulating" your previous "localhost" going to your general DocumentRoot declaration.
Something like this:
Listen 80 (already declared elsewhere)
Listen 8080
NameVirtualHost *:80
NameVirtualHost *:8080
<VirtualHost *:80>
ServerName mysite.local
...
</VirtualHost>
<VirtualHost *:8080>
ServerName localhost
DocumentRoot /same/as/the/classic/one/
...
</VirtualHost>
You could also declare some Alias /phpmyadmin/ which would be global be I don't recommend aliases because you couldn't have another phpmyadmin folder in one of your vhosts.
You can of course define a phpmyadmin.local vhost ;-)

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

Strange problem with Apache Virtual Hosts

I have recently installed Apache 1.3.41 on a Windows Vista machine. I have not changed the default settings in httpd.conf aprart from trying to setup virtual hosts, as follows:
Added some host names in the hosts file:
127.0.0.1 localhost
#::1 localhost
127.0.0.1 mysite
127.0.0.1 mydomain
I made the following folders in C:/Users/Moukasp/
C:/Users/Moukasp/Apache
C:/Users/Moukasp/django/mysite
Then added some simple html pages in each of those folder and the c:/Users/Moukasp/pictures folder and, finally, I added the following settings at the end of httpd.conf:
NameVirtualHost 127.0.0.1
<VirtualHost localhost>
# ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/Users/Moukasp/Apache"
ServerName localhost
Alias "/pics" "c:/users/moukasp/pictures"
Alias "/ap" "C:/Program Files/Apache Group/Apache/htdocs"
Alias "/dj" "C:/Users/Moukasp/django/mysite"
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost mysite>
# ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/Users/Moukasp/django/mysite"
ServerName mysite
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost mydomain>
# ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/Users/Moukasp/django/mysite"
ServerName mydomain
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
So, urls
http://localhost
http://localhost/pics
http://localhost/ap
http://localhost/dj
http://mydomain
work fine. But I there's no response from http://mysite which, as can be seen from the settings, serves from the same folder as http://mydomain. I have tried various names but no response. The hosts file is being read every time I start the Apache server. I even removed the mydomain server from the hosts file and the httpd.conf lest there's a limitation in the number of virtual hosts, but no luck.
Any help would be greatly appreciated, els I go mad! It is true, I have being trying this after complete failure to make Apache work with mod_python for django! I just hoped that a step at a time would lead to some success!
Try:
NameVirtualHost 127.0.0.1:80
In your httpd.conf. My config file includes a comment stating a port-specifier should be used.
The VirtualHost and NameVirtualHost directives should have IP addresses and ports:
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
# ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/Users/Moukasp/django/mysite"
ServerName mysite
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
Tried NameVirtualHost 127.0.0.1:80 but it doesn't make any difference! The only servers that work are localhost and mydomain.
I wonder whether I need to do something more than just declare the server name of each virtual host in the hosts file.
Try adding a port declaration to the hosts. For example:
<VirtualHost mydomain:80>
DocumentRoot "C:/Users/Moukasp/django/mysite"
ServerName mydomain
</VirtualHost>