I have configured many virtualhosts in my current apache2 server, in my local machine (Ubuntu 13.10).
Those are different local sites, with domains which are set in my /etc/hosts
:
127.0.0.1 localhost
127.0.0.1 agroplasticos.dev
127.0.0.1 resources.dev
127.0.1.1 luismasuelli-inspiron14
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Where the agroplasticos.dev
and resources.dev
sites were created by me, and the previous settings were set by default.
For localhost
, agroplasticos.dev
, and resources.dev
, I have site entries in /etc/apache2/sites-enabled
directory (only those 3 entries exist in this directory), which are links to the corresponding files in /etc/apache2/sites-available
:
agroplasticos.dev
looks like:
<VirtualHost agroplasticos.dev:80>
ServerName agroplasticos.dev:80
ServerAdmin webmaster@localhost
DocumentRoot /var/www/agroplasticos
<Directory /var/www/agroplasticos>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/agroplasticos-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/agroplasticos-access.log combined
</VirtualHost>
and resources.dev
looks like:
<VirtualHost resources.dev:80>
ServerName resources.dev:80
ServerAdmin webmaster@localhost
DocumentRoot /var/www/resources
<Directory /var/www/resources>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/resources-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/resources-access.log combined
</VirtualHost>
And -last but not least- localhost
looks like this:
<VirtualHost localhost:80>
ServerName localhost: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
</VirtualHost>
What I expect is that if I access such domains, they are resolved to 127.0.0.1 and they are served by apache using the different settings for each site. In particular, resources.dev
is just a static files website (it has only images I load externally via http from programs / scripts I'm making), so I don't care about even having PHP for such site. This means: I hit http://resources.dev/mirrorlings/images/sample.png
in my browser, and I retrieve an image.
However -and there's the catch- the site is successfully mounted if I have network connection. If i'm not connected, then:
- I can access
http://localhost/
(the sample, never-modified, "it works" screen appears). - I cannot access
http://resources.dev/
(the server did not mount it; http clients like browsers or ActionScript loaders cannot reach such url). - I cannot access
http://agroplasticos.dev/
(the server did not mount it; same about http clients). I'm getting this error log when running
sudo service apache2 restart
:[Sun Jul 20 15:39:55 2014] [error] (111)Connection refused: Could not resolve host name localhost -- ignoring! [Sun Jul 20 15:39:55 2014] [error] (111)Connection refused: Could not resolve host name agroplasticos.dev -- ignoring! [Sun Jul 20 15:39:55 2014] [warn] The Alias directive in /etc/apache2/conf.d/phpmyadmin.conf at line 3 will probably never match because it overlaps an earlier Alias. [Sun Jul 20 15:39:55 2014] [error] (111)Connection refused: Could not resolve host name agroplasticos.dev -- ignoring! [Sun Jul 20 15:39:55 2014] [error] (111)Connection refused: Could not resolve host name localhost -- ignoring! [Sun Jul 20 15:39:55 2014] [error] (111)Connection refused: Could not resolve host name resources.dev -- ignoring! apache2: apr_sockaddr_info_get() failed for luismasuelli-inspiron14 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [Sun Jul 20 15:39:56 2014] [error] (111)Connection refused: Could not resolve host name localhost -- ignoring! [Sun Jul 20 15:39:56 2014] [error] (111)Connection refused: Could not resolve host name agroplasticos.dev -- ignoring! [Sun Jul 20 15:39:56 2014] [warn] The Alias directive in /etc/apache2/conf.d/phpmyadmin.conf at line 3 will probably never match because it overlaps an earlier Alias. [Sun Jul 20 15:39:56 2014] [error] (111)Connection refused: Could not resolve host name agroplasticos.dev -- ignoring! [Sun Jul 20 15:39:56 2014] [error] (111)Connection refused: Could not resolve host name localhost -- ignoring! [Sun Jul 20 15:39:56 2014] [error] (111)Connection refused: Could not resolve host name resources.dev -- ignoring! apache2: apr_sockaddr_info_get() failed for luismasuelli-inspiron14 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Also do not understand why does this log appeared twice. You can see the same line block is repeated with one-second delay.
And my question here: Why do I need to have internet connection when what I want is that Apache resolved such fake domains as local, since they are in /etc/hosts
? What do I have to configure in order to allow local, networkless, resolution?
I was trying to develop without having internet connection and could not hit my local servers using local /etc/hosts
domain resolution to local (loopback) ip address.
VirtualHost *:80
instead ofVirtualHost <fdqn>:80
? – muru Jul 21 '14 at 05:51.dev
top level domain first, to see what DNS server is authorative for it. Not finding a server for your domains, it falls back to the hosts file. – Jos Jun 19 '16 at 14:48<VirtualHost *:80>
andServerName agroplasticos.dev
. I have explored this case, according to this post: http://askubuntu.com/q/824086/566421 – pa4080 Oct 19 '16 at 17:50