ServerAlias not working
Posted
by
Janis Peisenieks
on Server Fault
See other posts from Server Fault
or by Janis Peisenieks
Published on 2010-12-13T16:09:35Z
Indexed on
2010/12/22
15:56 UTC
Read the original article
Hit count: 402
I have a VPS, that I have configured to host multiple websites with name based hosting. It is all good while only using example.com, and www.example.com. It also works with example.net, but when I try example.net, it reverts to my default site configuration, which just shows my default (empty) index.html page.
Here's the default file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
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>
Here's a configuration for the example.com site:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
<Directory /srv/www/example.com/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And here is the config for the example.net site:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.net
ServerAlias www.example.net
DocumentRoot /srv/www/example.net/public_html/
ErrorLog /srv/www/example.net/logs/error.log
CustomLog /srv/www/example.net/logs/access.log combined
<Directory /srv/www/example.net/public_html/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Where could the problem be?
I believe, that there is something going wrong with the ServerAlias property.
Could it be because of the way the site's are built? Because example.com is a Joomla site, and example.net is a Zend Framework site. Just in case, I'll also insert the .htaccess files for example.net, since example.com has it's disabled: example.net:
SetEnv APPLICATION_ENV development
RewriteRule ^(browse|config).* - [L]
ErrorDocument 500 /error-docs/500.shtml
SetEnv CACHE_OFFSET 2678400
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Fri, 25 Sep 2037 19:30:32 GMT"
Header unset ETag
FileETag None
</FilesMatch>
RewriteEngine On
RewriteRule ^(adm|statistics) - [L]
RewriteRule ^/public/(.*)$ http://example.net/$1 [R]
RewriteRule ^(.*)$ public/$1 [L]
Any help would be greatly appreciated!
Edit So that my question is ABSOLUTELY clear: The problem is, that one site works with both www prefix as well as without it, and the second one does not. I would like to know how to enable the second site to work with www prefix as well.
© Server Fault or respective owner