VirtualHost always returns default host with Apache on Ubuntu 14.04

前端 未结 12 597
夕颜
夕颜 2021-01-30 07:16

I try to setup a virtual host besides the default localhost. Whenever I try to call my virtual host http://test I get the default Apache2 Index file t

12条回答
  •  执笔经年
    2021-01-30 07:50

    I was facing this issue, and it turned out I had to disable the default virtual host.

    sudo a2dissite 000-default.conf
    

    Possible Expanation:

    According to the apache documentation An In-Depth Discussion of Virtual Host Matching:

    [...] If the main server has no ServerName at this point, then the hostname of the machine that httpd is running on is used instead.

    That means if the default vhost (commonly 000-default.conf) has no ServerName set - which is the default - Apache will fallback to the hostname of the operating system.

    As a result, Apache selects and serves from the default vhost (000-default.conf) even though another user-created vhost with the same ServerName as the machine's hostname is configured.

    The reason is that Apache sorts the vhosts alphabetically by filename and chooses the first vhost configuration that matches the requested HTTP Host header. Thus, the 000-default.conf is checked before user-defined vhosts, as they are usually not prefixed with 000-.

提交回复
热议问题