Multiple Virtual Sites with Wampserver - virtualhost

I've having a problem creating multiple virtual hosts, I've edit C:\wamp\alias\web.local to look like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#website1.local
DocumentRoot "C:/Documents and Settings/username/workspace/www.website1.com"
ServerName website1.local
<Directory "C:/Documents and Settings/username/workspace/www.website1.com">
DirectoryIndex index.php index.htm index.html
Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#website2.local
DocumentRoot "C:/Documents and Settings/username/workspace/www.website2.com"
ServerName website2.local
<Directory "C:/Documents and Settings/username/workspace/www.website2.com">
DirectoryIndex index.php index.htm index.html
Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#website3.local
DocumentRoot "C:/Documents and Settings/username/workspace/www.website3.com"
ServerName website3.local
<Directory "C:/Documents and Settings/username/workspace/www.website3.com">
DirectoryIndex index.php index.htm index.html
Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#website4.local
DocumentRoot "C:/Documents and Settings/username/workspace/www.website4.com"
ServerName website4.local
<Directory "C:/Documents and Settings/username/workspace/www.website4.com">
DirectoryIndex index.php index.htm index.html
Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and my hosts file looks like this:
127.0.0.1 localhost
127.0.0.1 website1.local
127.0.0.1 website2.local
127.0.0.1 website3.local
127.0.0.1 website4.local
I've restarted Wampserver but I don't seem to be able to access website1.local, website2.local, website3.local or website4.local. I get a 'Network Error (dns_unresolved_hostname)' error message.
Please note localhost is the only one that seems to work.
Any help appreciated.
Regards,
Stephen
EDIT
I'm running Wampserver 2.2 on Windows XP.

Couple of problems, You dont create virtual hosts by editing that file.
You use this file c:\wamp\bin\apache\apache.2.x.y\conf\extra\httpd-vhosts.conf
then you uncomment the 'Include conf/extra/chris-vhosts.conf' from within the https.conf file, its near the bottom of the file.
Now the VHOST definitions you quote above look pretty good so you can probably just move then to the correct place and you a pretty good to go.
Except for
Is is a Very Very bad idea to use directory structures that contain spaces eg
DocumentRoot "C:/Documents and Settings/username/workspace/www.website3.com"
It is much safer to place your site code in a structure something like this
C:\websites\www\website3
C:\websites\www\website4
or even
D:\websites\www\website4
Oh and one more thing, you only need one reference to
NameVirtualHost *:80
Normally the first line of the vhost definition file.

Related

How can I keep a global ServerName in apache working?

The Apache documentation is a bit unclear on the vhost configuration. Where I normally use wampserver, I discovered a discrepancy with XAMPP. Consider the fairly standard httpd.conf in the XAMPP distribution containing among other things:
ServerName localhost:80
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
</Directory>
And a empty httpd-vhosts.conf file. Everything works as advertised and the content of the xamp/htdocs folder is used (and redirects to /htdocs/dashboard)
As soon as a section is added to file httpd-vhosts.conf, for instance
<VirtualHost *:80>
ServerName customer01.localhost
DocumentRoot "D:/Customers/Customer01/httpdocs"
<Directory "D:/Customers/Customer01/httpdocs">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
And the proper amendments are made to .../etc/hosts. http://localhost stops working as it now redirects to D:/Customers/Customer01/httpdocs ignoring the ServerName setting in httpd.conf.
Is this by design?
If, however, in addition to the ServerName setting in httpd.conf the following is added to httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
things are fine again.
Why is the extra vhost needed as the global ServerName is already set in httpd.conf? Is this something the ApacheFriends should add to vhost by default?

Virtualhost wildcard subdomain of wildcard subdomain in apache2.4

Currently, I have worked wildcard subdomain config like below:
<VirtualHost *:80>
ServerAlias *.domain
ErrorLog /tmp/error.log
CustomLog /tmp/access.log combined
VirtualDocumentRoot /var/www/%1/public
<Directory "/var/www">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
but if I enter sub.sub.domain will return to the default vhost. How to configure to the main/root domain's path? I tried below conf but still not worked:
<VirtualHost *:80>
ServerAlias *.*.domain
ErrorLog /tmp/error.log
CustomLog /tmp/access.log combined
VirtualDocumentRoot /var/www/%2/public
<Directory "/var/www">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I changed %2 to %1 still doesn't work.
What is right syntax?
The above code has the right syntax but I just put it to the wrong placement order. So the correct answer is to put the second one to the top above the first one.
Below full config example :
<VirtualHost *:80>
ServerAlias *.*.domain
ErrorLog /tmp/error.log
CustomLog /tmp/access.log combined
VirtualDocumentRoot /var/www/%2/public
<Directory "/var/www">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.domain
ErrorLog /tmp/error.log
CustomLog /tmp/access.log combined
VirtualDocumentRoot /var/www/%1/public
<Directory "/var/www">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Apache is skipping/ignore the same subdomain/domain config by ascending order from the top. sub.sub.domain is also a part of *.domain , so if I want to configure it I must put the config in the top or if use different file config use lower number name.
Multiple ServerAlias or ServerName or NameVirtualHostlines will yield a "NameVirtualHost *:80 has no VirtualHosts" warning. Apache will ignore the second directive and use the first defined NameVirtualHost line, though. This seems to happen when one is using multiple virtual host configuration files and doesn't understand that you only need to define a particular NameVirtualHost line once
reference
Simple solution but I workaround for some hours and I hope it helps other people like me.

Apache vhost not working for subdomains

I have this configuration but both url app.test.com & stage.test.com
redirect to same code/deployment
<VirtualHost *:80>
ServerName app.test.com
DocumentRoot /var/www/html/Test-Prod/web
<Directory "/var/www/html/Test-Prod/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-prod__error_log
CustomLog logs/test-prod_access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName stage.test.com
DocumentRoot /var/www/html/Test/web
<Directory "/var/www/html/Test/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-website_error_log
CustomLog logs/test-website_access_log common
</VirtualHost>
The usual error for this is leaving out the NameVirtualHost directive if you're still using httpd 2.2
Add the following in your config file and it'll probably work
NameVirtualHost *.80
You might want to read the documentation for Named-based Virtual Host Support with httpd 2.2.
NameVirtualHost *.80
<VirtualHost localhost:80>
ServerName color
ServerAlias localhost
ServerPath "C:/wamp/www/subwww/color"
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www/subwww/color">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
in above code, subdomain name is color
and the url is http://color.localhost/
if the operating system is windows then add "127.0.0.1 color.localhost" in "C:/windows/system32/dirvers/etc/hosts" with notepad run as administration

2 domains pointing to 1 server (2 different subfolders)

OK, so, I think the title is rather self-explanatory.
I've set up my own Apache server (on Debian) and hosting 2 different sites (let's say mysite1.com at /home/www/mysite1, and mysite2.com at /home/www/mysite2).
In my domain name registrar setup page (Dynadot actually), I created A records (still not sure what this is exactly...) for both of them, pointing to my server's ip...
Now, on the server's side, here'e what my .conf file looks like (/etc/apache2/sites-enabled/mysite actually)
<VirtualHost *:80>
DocumentRoot /home/www/mysite1.com
ServerName www.mysite1.com
ServerAdmin drkameleon#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/www/mysite1.com>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin
<Directory "/home/www/mysite1.com/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot /home/www/phpmyadmin
ServerName www.mysite1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/www/mysite2.com
ServerName www.mysite2.com
ServerAdmin drkameleon#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/www/mysite2.com>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Now, the thing is. Now matter which site I visit (1 or 2), I always get mysite1's contents.
What am I doing wrong? Any ideas?
There are multiple possibilities of what could go wrong.
Do you have
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
somewhere in the config? (http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost)
Without that config entry Apache is not sensitive to domain names in dispatching requests to virtual hosts.
It's just a guess.
Make sure Apache has been reloaded after any changes to the config!

Linux virtualhost subdirectories not working

I can only access 1 website '/resume/', sub directory websites are not visible externally? The site '/resume2/' tries to point to /resume/. All the sub sites are trying to point to /resume/
<VirtualHost *:80>
ServerName resume
ServerAlias resume
DocumentRoot "/var/www/html/resume/"
<Directory /var/www/html/resume/>
DirectoryIndex index.php phpinfo.php index.html index.htm
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName resume2
ServerAlias resume2
DocumentRoot "/var/www/html/resume2/"
<Directory /var/www/html/resume2/>
DirectoryIndex index.php phpinfo.php index.html index.htm
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I'm pretty sure you should define different hostnames/IPs or port behind the VirtualHost tag, e.g.
<VirtualHost resume.mydomain.de:80>
ServerAlias resume
ServerName resume.mydomain.de
DocumentRoot "/var/www/html/resume/"
...
</VirtualHost>
<VirtualHost resume2.mydomain.de:80>
ServerAlias resume
ServerName resume.mydomain.de
DocumentRoot "/var/www/html/resume2/"
...
</VirtualHost>
... where resume.mydomain.de and resume2.mydomain.de are resolved to two different IP that are both configured on your host. You could also use the same IP and different port. Anyhow, keep in mind that you need to add a listen tag to your configuration for each VirtualHost.
Hope that helps! Cheers ...