Apache2 + 禁用默认虚拟服务器

And*_*rej 5 virtualization apache-2.2

这是我第一次尝试自己设置服务器。

到目前为止,一切都运行良好。我添加了一个新的虚拟服务器并更改了我的域的 A 记录,现在它按预期工作。

但是:我想“阻止”访问默认的 www 目录(在我的情况下var/www)。现在,当我输入服务器 IP 而不是域时,我会进入默认的 www 目录 - 我想禁用它。

我不想设置重定向,但只是禁止用户、搜索引擎等在访问时查看任何内容 http://myip/

目前我正在通过添加一个空来解决这个问题index.html,但我想实际上阻止所有请求并且只允许访问我的域(它们位于像“ var/www/sites/domain.com/www”这样的子目录中)

我希望你明白我的意思——我的英语很烂:/

ps 因为我安装了 webmin 并通过它访问它http://myIp:webminPort- 我想我实际上只想阻止端口 80,但不确定...

iai*_*lbc 5

您需要保持端口 80 打开,因为 domain.com/www 虚拟主机的所有内容也通过 80 传输。

apache 有一个默认的 vhost 设置,你只需要在你的 httpd.conf 中注释掉它。

在 webmin 中编辑配置:

 Webmin -> Servers -> Apache Website -> Global Configuration
Run Code Online (Sandbox Code Playgroud)

慢慢地通读它,你会发现默认的 vhost 代码块,只需将其注释掉即可。这是值得的,因为您以后可能想要调整设置。

Andre(OP) 确定默认虚拟主机定义在 /sites-enabled/default-000

这是您要查找的部分:

### Section 2: 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
Run Code Online (Sandbox Code Playgroud)

使用散列注释掉第 2 节中的这些指令:

#ServerName
#<Directory />
#<Directory>
#---comment out all contents of this directory block---
#<Directory /var/www/html>
#---comment out all contents of this directory block---
#</Directory>
#DocumentRoot
Run Code Online (Sandbox Code Playgroud)