6

I am using Debian have server with canonical name (defined in /etc/hostname and in reverse DNS) server.example.com

root@server:~# uname -a
Linux server.example.com 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1 (2015-05-24) x86_64 GNU/Linux

Apache/2.4.10 (Debian) Server at server.example.com Port 80

Now I installed apache2 and did some basic configuration. Then I added VirtualHosts to /etc/apache2/sites-available with symlinks in sites-enabled. Everything is working fine except VirtualHost with ServerName server.example.com. When I try to access that URI in explorer, I get content of default virutal host (with no ServerName specified). If I change server.example.com.conf's ServerName to something different (like test.example.com) and reload apache configuration, then I can get to the URI with no problems. I would like to know what is wrong in having VirtualHost's ServerName same as canonical name of the machine.

Moreover, server.example.com.conf has DocumentRoot /var/www/subs/server which contains index.html and munin folder. Default VirtualHost has DocumentRoot /var/www/html which has no munin folder in it. However, when I try to access http://server.example.com/munin I can get into /var/www/subs/server/munin, while http://server.example.com/index.html brings me /var/www/html/index.html.

Lastly, when I put Redirect 404 / in default VirtualHost, I will get 404 when I try to access both http://server.example.com/ and http://server.example.com/munin

Added configuration of VirtualHosts

/etc/apache2/sites-available/forum.example.com.conf :

# Working subdomain configuration
<VirtualHost *:80>
        ServerName forum.example.com
        ServerAdmin zereges@example.com
        DocumentRoot /var/www/subs/forum
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/sites-available/server.example.com.conf :

# Not working server.example.com configuration
<VirtualHost *:80>
        ServerName server.example.com
        ServerAdmin zereges@example.com
        DocumentRoot /var/www/subs/server
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/sites-available/default.conf :

# Default VirtualHost configuration 
<VirtualHost *:80>
        ServerAdmin zereges@example.com
        DocumentRoot /var/www/html
        #Redirect 404 /
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

root@server:~# apache2ctl -t
Syntax OK


Added ouptut of root@server:~# apache2 -S

[Tue Aug 11 11:07:32.705684 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
[Tue Aug 11 11:07:32.706119 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Tue Aug 11 11:07:32.706250 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Tue Aug 11 11:07:32.706406 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Tue Aug 11 11:07:32.706566 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
(... repeating few more times)
[Tue Aug 11 11:07:32.744292 2015] [core:warn] [pid 20215] AH00111: Config variable ${APACHE_LOG_DIR} is not defined

AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

While,

/etc/apache2/apache2.conf:74:Mutex file:${APACHE_LOCK_DIR} default
/etc/apache2/envvars:21:export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX


After running /etc/apache2/envvar I get this by executing apache2 -S

VirtualHost configuration:
*:80     is a NameVirtualHost
         default server server.example.com (/etc/apache2/sites-enabled/default.conf:1)
         port 80 namevhost server.example.com (/etc/apache2/sites-enabled/default.conf:1)
         port 80 namevhost download.example.com (/etc/apache2/sites-enabled/download.example.com.conf:1)
         port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com.conf:1)
                 alias www.example.com
         port 80 namevhost forum.example.com (/etc/apache2/sites-enabled/forum.example.com.conf:1)
         port 80 namevhost forumold.example.com (/etc/apache2/sites-enabled/forumold.example.com.conf:1)
         port 80 namevhost forumtest.example.com (/etc/apache2/sites-enabled/forumtest.example.com.conf:1)
         port 80 namevhost mail.example.com (/etc/apache2/sites-enabled/mail.example.com.conf:1)
         port 80 namevhost ro.example.com (/etc/apache2/sites-enabled/ro.example.com.conf:1)
         port 80 namevhost server.example.com (/etc/apache2/sites-enabled/server.example.com.conf:1)
         port 80 namevhost anotherexample.com (/etc/apache2/sites-enabled/anotherexample.com.conf:1)
                 alias www.anotherexample.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
4
  • Please post the relevant sections of your apache configuration here (the entirety of each <virtualhost> directive). Additionally please include the output of httpd -t and check the apache error log for any relevant errors.
    – Gene
    Aug 7, 2015 at 14:39
  • The output of apache2 -S would likely be instructive.
    – womble
    Aug 11, 2015 at 2:00
  • @womble I edited my question.
    – Zereges
    Aug 11, 2015 at 9:04
  • And that info, combined with @covener's answer, should be everything you need to solve your problem.
    – womble
    Aug 11, 2015 at 22:43

2 Answers 2

4
+50

On debian based distributions, the default virtualhost specifies no ServerName at all, which effectively means it ends up with the systems hostname as its ServerName.

Since it's listed first, it's going to cover up any later vhost with that same ServerName.

I'd suggest disabling the shipped default virtual host and adding your own that speecifies a servername but doesn't use the ServerName you're interested in.

1
  • I edited my question so that it more resembles what it looks like.
    – Zereges
    Aug 9, 2015 at 14:53
0

From apache-doc: If no ServerName is specified, then the server attempts to deduce the hostname by performing a reverse lookup on the IP address. If no port is specified in the ServerName, then the server will use the port from the incoming request. For optimal reliability and predictability, you should specify an explicit hostname and port using the ServerName directive.

+

Essentially, the main server is treated as "defaults" or a "base" on which to build each vhost. But the positioning of these main server definitions in the config file is largely irrelevant -- the entire config of the main server has been parsed when this final merging occurs. So even if a main server definition appears after a vhost definition it might affect the vhost definition.

3
  • I thought, that I can set configuration being default by leaving ServerName undefined. So how do I define configuration for default virtual host?
    – Zereges
    Aug 7, 2015 at 21:20
  • 1
    So you have a set of VirtualHost tags using *:80. The first of those is the default for that group. If you specify that differently for soem VirtualHosts (e.g. *:443), then a different default exists for that group of VirtualHosts. It's common to use a naming convention between files in your /etc/apache2/sites-enabled directory or equivalent such that the first by lexical order is reliably your default host.
    – mc0e
    Aug 8, 2015 at 12:46
  • @mc0e I edited my question so that it more resembles what it looks like.
    – Zereges
    Aug 9, 2015 at 14:53

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.