Help running multiple websites on apache2
Apache newb here. I've read a few tutorials and I'm not sure what I'm doing wrong.
I have my default site enabled, and that one works fine:
<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>
So I wanted to add a second site, www.example.com. I updated my hosts file:
192.168.1.148 sam-NV53 # Added by NetworkManager
127.0.0.1 localhost.localdomain localhost
::1 sam-NV53 localhost6.localdomain6 localhost6
127.0.1.1 sam-NV53
www.example.com localhost.localdomain localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
And I defined my new website
<VirtualHost *>
ServerAdmin [email protected]
ServerName www.example.com
ServerAlias example.com
DirectoryIndex index.html
DocumentRoot /var/www/
</VirtualHost>
Since the DocumentRoot
for my new site is the same as the one for my default site, I'd expect to see the index.html
from my default site. But instead, I see the example.com from the web. What am I missing here?
Edit
Apparently nobody has noticed that my entry in my hosts file is backwards. I changed it to:
127.0.0.1 geekspeak.dev
Now it works. Thanks everyone for your input :)
whatever is in your
<VirtualHost>
must match with what you have listed for
NameVirtualHost
So if you have
NameVirtualHost *:80
All your virtualhost entries for port 80 must look like
<VirtualHost *:80>
So switch * to *:80 like is in your first example and it should go to the correct place