To see my description of my problem directly, see the Problem part.
Running XUbuntu 14.10 and Apache 2.4.10.
I'm quite new to Apache so I'm trying to setup simple VH...with some success but I still have an issue. I read the docs and can't find what's wrong with my config. I would like to configure two virtual hosts : myname.com and penguin.com.
Here is a short description (not exhaustive) of my current configuration.
<Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options +Indexes Options FollowSymLinks AllowOverride None Require all granted </Directory> <Directory /var/www/html/flashlight/> AllowOverride All </Directory> <FilesMatch "^\.ht"> Require all denied </FilesMatch> # Include generic snippets of statements IncludeOptional conf-enabled/*.conf # Include the virtual host configurations: IncludeOptional sites-enabled/*.conf
<VirtualHost *:80> ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html <Directory /var/www/> AuthName "Mon domaine" AuthType Basic AuthUserFile /etc/apache2/users.passwd Options +Indexes Options FollowSymLinks AllowOverride None Require valid-user </Directory> </VirtualHost>
<VirtualHost 127.0.0.2:80> ServerName myname.com ServerAlias www.myname.com DocumentRoot /var/www/html/myname <Directory /var/www/html/myname> Options +Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> </VirtualHost>
<VirtualHost 127.0.0.3:80> ServerName penguin.com ServerAlias www.penguin.com DocumentRoot /var/www/html/penguin <Directory /var/www/html/penguin> Options +Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> </VirtualHost>
Both virtual hosts were enabled as described in the Apache docs using
a2ensite. Apache was restarted with
/etc/init.d/apache2 graceful. In
/var/www/html/myname I created simple
index.html files to check if I'm on a virtual host or not.
Finally, I changed
/etc/hosts to contain:
127.0.0.1 localhost 127.0.0.2 myname.com 127.0.0.3 penguin.com
To check the configuration, I run
apachectl -S and can see :
VirtualHost configuration: 127.0.0.3:80 penguin.com (/etc/apache2/sites-enabled/penguin.conf:1) 127.0.0.2:80 myname.com (/etc/apache2/sites-enabled/myname.conf:1) *:80 www.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
Now that I have two Virtual hosts configured, I try to access them.
When I try to access
penguin.com in my broswer (Firefox), I see the
/var/www/html/index.html instead of
/var/www/html/penguin/index.html. I have to explicitely write
penguin.com/index.html to see the correct index page.
But when I access
myname.com, the right index is served !?
Moreover, when I access those sites with Chrome, this problem doesn't occur and I see the right index page directly.
Is there a problem with my Apache config ? Or Do you think it's related to Firefox only (maybe it doesn't read
/etc/hosts correctly) ?
Just forgot to mention that when I access page via IP (127.0.0.2/3) I have the same issue in Firefox (only 127.0.0.2 works).
wget, I get the files as expected. So I guess it may be related to browsers and not Apache config.
To "solve" the problem I replaced the loopback addresses in /etc/hosts with my local ip address. In addition I replaced the VirtualHost declaration by
<VirtualHost *:80> in both files. Works fine now !
I still wonder why the Firefox couldn't get the right index when given the full loopback ip address though.
Sorry for the long post !