0

I know it is a question asked several times, but I've read them all and not solved the problem.

I have configured the virtualhost apache like this:

sudo nano /etc/apache2/sites-available/example.loc

<VirtualHost *:80>
ServerName example.loc
ServerAlias www.example.loc

DocumentRoot /var/www/example/web
<Directory /var/www/example/web>
    AllowOverride All
    Order allow,deny
    Allow from All
</Directory>

ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined

I put this in the /etc/hosts file:

127.0.0.1   localhost
127.0.0.1   example.loc

and then I loaded the site in this way:

sudo a2ensite example.loc

and restarted apache.

If I go to example.loc, it works properly, but if I go to www.example.loc, it does not work, saying that it is "impossible to find www.example.loc"!

Have I done something wrong in the configuration?

1 Answer 1

3

The entries to /etc/hosts are not "inclusive", so your addition of example.loc does not include www.example.loc (or any other subdomain) as well. So, your browser tries to find www.example.loc the usual way, which is by asking the name server(s) you have configured. But of course no nameserver knows anything about this domain. Your local Apache never gets into action this way ;)

As an additional remark, adding names to /etc/hosts this way might bring problems in another regard as well. The line 127.0.0.1 example.loc will probably override the line 127.0.0.1 localhost, so you might get problems resolving localhost. You can assign several names to an ip in one line, so the proper way would be

127.0.0.1 localhost example.loc www.example.loc
1
  • nice! ...I was facing the same issue for last couple of hours! :) Mar 19, 2015 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .