I am using Ubuntu so httpd.conf is not used, instead everything is configured in:
apache2.conf +
ports.conf (which contains the NameVirtualHost *:80 directive)
+ mods-enabled dir
+ sites-enabled dir
In the sites-enabled dir the 000-default file includes the following Virtual Server directives:
# Virtual Host Directives
ServerAdmin me@example
<VirtualHost *:80>
ServerName www.example1.co.uk
DocumentRoot /var/www/example/example1dir
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/example/example1dir/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
AuthName "Welcome to the Example 1 Website. Please Log In"
AuthType basic
AuthUserFile /var/www/.example1htusers
require valid-user
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#LogLevel warn
Loglevel debug
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
# Second Host
<VirtualHost *:80>
ServerName www.example2.co.uk
DocumentRoot /var/www/example/example2dir
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/example/example2dir/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/cbeherror.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#LogLevel warn
Loglevel debug
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
If I do a get for the following index.php file via: www.example1.com/index.php
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
}
?>
I can see that %HTTP_HOST
contains the static IP address that my DNS provider redirects to e.g.
101.202.303.404
On the other hand %HTTP_REFERER contains:
www.example1.co.uk or www.example2.co.uk depending on the site requested.
I think Apache is looking at %HTTP_HOST to decide which virtual server to assign.
It never finds a match and therefore defaults to the first Virtual Server
i.e. www.example1.co.uk
So, if I can manipulate the Header to put the contents of %HTTP_REFERER into %HTTP_HOST
before Apache checks the ServerName then I think I should get the right VirtualHost assigned.
I tried asking the DNS provider for some help. Because they don't host anything on
my behalf they won't even look at it........
Many thanks for your help.