0

To see my description of my problem directly, see the Problem part.

Context:

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.

Configuration

Here is a short description (not exhaustive) of my current configuration.

/etc/apache2/apache2.conf

<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

/etc/apache2/sites-enabled/000-default.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>

/etc/apache2/sites-enabled/myname.conf

<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>

/etc/apache2/sites-enabled/penguin.conf

<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/penguin and /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)

Problem

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) ?

EDIT

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).

With wget, I get the files as expected. So I guess it may be related to browsers and not Apache config.

EDIT2

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 !

Thank you

5
  • you can try using 172.0.0.3 in firefox if that working. Also look into apache access log and error log for hints. Oct 7, 2015 at 10:01
  • I edited my post, but the behaviour is really weird in both cases.
    – Gordak
    Oct 7, 2015 at 10:03
  • i have posted an answer, try and mark as answer if that resolved your problem. Oct 7, 2015 at 10:14
  • I modified my /etc/hosts and replaced the loopback addresses with my local ip address and modified the VH declaration to <VirtualHost *:80>. Works fine with both browsers !
    – Gordak
    Oct 7, 2015 at 10:43
  • can you cut the EDIT2 into an answer and accept that ?
    – niceman
    Mar 13, 2017 at 8:27

1 Answer 1

0

In this case firefox will check your /etc/hosts as last option for name resolution.

You can try this workaround.

  1. Open firefox and enter about:config in the URL.
  2. Search keyword.enabled and set it to False.
  3. Make sure in /etc/nsswitch.conf, hosts entry having files as first option.
2
  • Hey. Thank you for your answer. It doesn't seem solve the issue though. I tried with wget and it seems to work fine. Do you think it's related to browsers interaction with /etc/hosts and not the apache config ?
    – Gordak
    Oct 7, 2015 at 10:22
  • Yes this has to be the browser issue. If this is an httpd issue, it wont be isolated to only Firefox. Can you provide /etc/hosts entry here? Oct 7, 2015 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.