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 ;-)
Related
Have spent ages trying to figure this out, we're looking to add cloud.domainname.co.nz, the records are all setup, however when you search cloud.domainname.co.nz, it shows you the domainname.co.nz website, and not the one where the directory is set?
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName domain.co.nz
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks ExecCGI Includes
Order allow,deny
Allow from all
</Directory>
Redirect permanent / https://domain.co.nz/
SSLEngine on
SSLCertificateFile C:\xampp\apache\conf\domain.co.nz.crt
SSLCertificateKeyFile C:\xampp\apache\conf\domain.co.nz.key
SSLCertificateChainFile C:\xampp\apache\conf\domain.co.nz.ca-bundle
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/cloud"
ServerName cloud.domain.co.nz
ServerAlias cloud.domain.co.nz
<Directory "C:/xampp/cloud">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Have gone through many other peoples questions/answers and after trying those I still wasn't able to get it working properly, can't figure out why!!
I've also noticed people show their vhosts when trying to figure out similar issues so I've put it below..
127.0.0.1 cloud.localhost
127.0.0.1 domain.co.nz
127.0.0.1 cloud.domain.co.nz
I solve it by adding this to the virtual host configuration
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
DocumentRoot "D:/htdocs/"
ServerName localhost
</VirtualHost>
NameVirtualHost is so we can use the same port for multiple virtual hosts configurations. Setting up the usual domain for localhost is the key here. I am not sure why, but it solves the bug.
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!
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
I need to install a server with Apache 2.2 on Linux and I need to do two VirtualHosts differentiated by URI.
But with only one domain name and one ip address. And I can't use Alias.
I tried something like that but that doesn't work :
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName localhost/app1
ServerAlias www.localhost/app1
<Directory /var/www/app1>
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/app2
ServerName localhost/app2
ServerAlias www.localhost/app2
<Directory /var/www/app2>
Allow from all
</Directory>
</VirtualHost>
Thank you to the first answer here, it's working : https://serverfault.com/questions/588841/two-apps-on-apache-server-with-uri
I put the answer here if one day the link doesn't work :
What you could do is set up a reverse proxy to different virtual hosts listening only on loopback.
You would get in your www.localhost virtualhost:
<VirtualHost *:80>
DocumentRoot /var/www/
ServerName localhost
ServerAlias www.localhost
ProxyPassReverse /app1/ http://webapp1.local/
ProxyPassReverse /app2/ http://webapp2.local/
</Virtualhost>
And create two virtualhosts for the apps:
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/app1
ServerName webapp1.local
<Directory /var/www/app1>
Allow from all
</Directory>
</Virtualhost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/app2
ServerName webapp2.local
<Directory /var/www/app2>
Allow from all
</Directory>
</Virtualhost>
Make sure to add webapp1.local and webapp2.local to your /etc/hosts file.
Since you have only a single domain name and only a single ip address available there is no means for the apache server to distinguish which host is meant. Therefore there is noo sense in defining VirtualHosts here.
However you certainly can place two apps in separate folders inside your DocumentRoot:
ServerName whatever-your-domain.is
DocumentRoot /var/www
<Directory /var/www/app1>
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/app2>
Order allow,deny
Allow from all
</Directory>
Then you'd call those apps by their paths:
apps1: http://whatever-your-domain.is/app1
apps2: http://whatever-your-domain.is/app2
Don't forget to take care of requests to the "main folder" of that single host: /var/www which can be reached by http://whatever-your-domain.is/
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>