0

I am using Uubntu 16.04, with Apache2 (version 2.4) on my local personal laptop for development purpose. I have added a virtual host (hehe) under sites-enabled directory.

Since I have added it, I have troubles accessing http://localhost from Firefox but not Chrome.

In Chrome, when accessing http://localhost I get the root web directory correctly and http://hehe brings me to the new virtualhost directory.

In Firefox accessing http://localhost brings me ALSO to the /hehe directory of the virtualhost.

Attached are the two files. Very strange, but it must be something in my virtualhost configuration.

000-default.conf

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /home/xxx/myprojects/web

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<Directory /home/xxx/myprojects/web/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order deny,allow
        #Allow from all
    Require ip 127.0.0.1
    Require ip ::1
</Directory>

001-hehe.conf

NameVirtualHost hehe:80
<VirtualHost hehe:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName hehe

    ServerAdmin webmaster@localhost
    DocumentRoot /home/xxx/myprojects/web/understandmydreams

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<Directory /home/xxx/myprojects/web/understandmydreams/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order deny,allow
        #Allow from all
    Require ip 127.0.0.1
    Require ip ::1
</Directory>

Any idea how I can have both localhost and a virtualhost ??

0

Don't do that:

NameVirtualHost hehe:80
<VirtualHost hehe:80>

It's not doing the thing you are intending, but can cause hard-ish problems on future apache restarts (it introduces dependency on name resolution). It's very rarely used due to contrived implications.

You can and should declare a duplicate clause:

NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost

followed by

NameVirtualHost *:80
<VirtualHost *:80>
ServerName hehe
1

Try enabling the "ServerName" directive in 000-default.conf pointing to localhost.

As explained Here It is best to always explicitly list a ServerName in every name-based virtual host.

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.