a2dissite 000-default.conf 之后仍可访问默认页面

a2dissite 000-default.conf 之后仍可访问默认页面

我安装了全新安装的 Ubuntu 16.04 LTS 服务器(32 位),并启用了 LAMP 软件包。这意味着,它在开箱即用的情况下,在端口 80 上提供典型的 Apache2 Ubuntu 默认页面,位于 下/var/www/html/index.html

我做的第一件事就是尝试禁用该页面,使用古老的

sudo a2dissite 000-default.conf

命令,这促使我这样做

service apache2 reload

我也跟注了sudo

令我惊讶的是,在此之后,该网站仍然可以访问:在 Firefox 中重新加载和按 Shift 重新加载仍然显示该页面,并且我可以在 中看到请求/var/log/apache2/other_vhosts_access.log

a2dissite再次运行该命令显示Site 000-default already disabled目录/etc/apache2/sites-enabled/为空。

我究竟做错了什么?

编辑:

至于Julius Š 的建议。,我也试过

sudo service apache2 restart

结果相同,并检查了我的/etc/apache2/apache2.conf文件,该文件<VirtualHost>仅显示在某些评论中。

至于<Directory>条目,这些只是文件中的默认设置:

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>

可能是一些插件在/var/www/子文件夹中搜索合适的 html 文件?

编辑2:

我也reboot下载了机器,网站仍然可以访问。

只有停止服务才能使其无法访问。由于我计划在其上运行其他网站,因此最终需要运行它,所以我真的很好奇发生了什么。

编辑3:

正如我发现的这个答案,配置文件中的虚拟主机设置可以显示如下:

. /etc/apache2/envvars
apache2 -S

...就我而言,输出以下内容:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

DocumentRoot我对指向的条目有点怀疑/var/www/html,所以我做了一个

find |xargs grep DocumentRoot 2>/dev/null

文件夹中/etc/apache2,从而导致以下情况:

./sites-available/default-ssl.conf:     DocumentRoot /var/www/html
./sites-available/000-default.conf: DocumentRoot /var/www/html

...因此,包含该字符串的任何子文件夹中都没有任何内容。当似乎没有启用任何内容时,*-enabled/我真的很想知道 Apache 从哪里获取的。DocumentRoot

答案1

DocumentRoot默认值如果没有设置则使用。这意味着即使DocumentRoot配置中没有设置,Apache 也会从某个目录中提供服务。

对于上游 Apache 源来说,这/usr/local/apache/htdocsUbuntu 打包会覆盖该--enable-layout=Debian。这大概就是为什么它继续以 为 提供服务的原因/var/www/htmlDocumentRoot如果您只是希望它停止加载该页面,请www-data通过更改权限使用户无法访问它,或将其设置DocumentRoot为其他目录。

答案2

我对 muru 的回答有些困惑,于是找到了另一种解决方案。与 fkraiem 的评论不同,我想为非 80 端口安全代理设置 VPS,并添加虚拟站点配置文件来执行此操作。

注释掉删除了对默认 apache 成功页面的访问的Listen 80行。/etc/apache2/ports.conf

#Listen 80

这很好,假设您已将其添加Listen <secure-port-number>到虚拟站点 conf 文件的顶部。

systemctl restart apache2或者可能systemctl reload apache2像往常一样需要。

答案3

因为我计划在其上运行其他网站...

只要您创建一个或多个虚拟主机(并保持默认主机禁用),其中一个虚拟主机将被视为默认主机。在这种情况下使用哪个虚拟主机可能看起来有点随机,但事实并非如此:启用的主机配置按字母顺序读取,并且对于每个端口(即,如果您使用 http 和 https 的标准端口,则分别读取端口 80 和端口 443),以这种方式遇到的第一个虚拟主机将充当默认主机的角色。

因此,如果您稍后为端口 80BBB.conf定义,为端口 443定义,以及为 80 和 443定义,则会告诉您 www.foo.example 是端口 80 的默认设置,而 www.bar.example 是端口 443 的默认设置。除非后者配备了通配符证书,否则这可能不是特别有用,并且 www.foo.example 对端口 80 的偏好可能是不受欢迎的(或者如果需要,请不要惊讶于稍后添加对此的更改)。www.foo.exampleCCC.confwww.bar.exampleDDD.confwww.baz.exampleapache2 -SAAA.conf

因此我的建议是保持默认主机(其配置文件名故意排在字母表的前面)并更改其内容以显示有用的默认页面或更改其权限以显示有用的错误页面。(不要简单地删除,/var/www/html/index.html因为默认情况下,这会让您将肯定不需要的目录列表作为起始页)。

相关内容