How do I setup “name based” virtual hosts using Ubuntu 12.04?
I have followed the instructions given at https://help.ubuntu.com/12.04/serverguide/httpd.html#http-configuration .
I've done the following...
cp default newsite
- replace “/var/www” with “/var/www/newsite” in newsite
- add “ServerName newsite.example.com” to newsite
After some research, I found a blog entry that stated I needed to disable the default site using a2dissite default
. After I did that, it worked. Is that correct? This is never mentioned in the Ubuntu server guide. The guide also includes this line...
“The default virtual host has no ServerName directive specified, so it will respond to all requests that do not match a ServerName directive in another virtual host.”
Which seems to imply that both the default site and others can co-exist.
I'm running a fresh install of 12.04 Server and have reloaded the apache config each time I made an adjustment.
In summary... after adding a new file under /etc/apache2/sites-available (an altered copy of the “default” file with the ServerName directive added) and the corresponding symlink under /etc/apache2/sites-enabled, is it necessary to disable or rename the default site symlink in order for the new site to function? The documentation and one answer given below seems to infer that it is not necessary to do so, but if so, what have I done wrong? Using the config below, when trying to access newsite.example.com I get the default site.
/etc/apache2/sites-available$ cat default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
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 ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/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>
/etc/apache2/sites-available$ cat newsite
<VirtualHost *:80>
DocumentRoot /var/www/newsite
ServerName newsite.example.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/newsite/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/sites-enabled# ls -l
root@sandbox:/etc/apache2/sites-enabled# ls -l
total 0
lrwxrwxrwx 1 root root 26 Mar 18 09:56 000-default -> ../sites-available/default
lrwxrwxrwx 1 root root 26 Mar 7 13:36 newsite -> ../sites-available/newsite
sites-available
it is not clear what you have undersites-enabled
. I suggest tocat
files undersites-enabled
since these are the ones apache actually loads.