Apache 2.4:如何提供虚拟主机,但不提供实际的服务器主机名?

Apache 2.4:如何提供虚拟主机,但不提供实际的服务器主机名?

我有一台运行 apache 2.4 的 ubuntu 16 服务器。该服务器的主机名是组织规定的丑陋代码,对我们的最终用户毫无意义,因此我为该服务器托管的三个站点创建了描述性 CNAMES,并使用这些 CNAMES 配置了虚拟主机。我000-default.conf为丑陋的主机名配置了文件,并Require all denied为空/var/www/html目录配置了 。

apachectl -S(已编辑)的输出如下:

# apachectl -S
VirtualHost configuration:
*:443                  is a NameVirtualHost
         default server UGLYNAME.domain.org (/etc/apache2/sites-enabled/000-default-le-ssl.conf:2)
         port 443 namevhost UGLYNAME.domain.org (/etc/apache2/sites-enabled/000-default-le-ssl.conf:2)
         port 443 namevhost VHOST1.domain.org (/etc/apache2/sites-enabled/VHOST1-premove-le-ssl.conf:2)
         port 443 namevhost VHOST2.domain.org (/etc/apache2/sites-enabled/VHOST2-le-ssl.conf:2)
         port 443 namevhost VHOST3.domain.org (/etc/apache2/sites-enabled/VHOST3-le-ssl.conf:2)
*:80                   is a NameVirtualHost
         default server UGLYNAME.domain.org (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost UGLYNAME.domain.org (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost VHOST1.domain.org (/etc/apache2/sites-enabled/VHOST1.conf:1)
         port 80 namevhost VHOST2.domain.org (/etc/apache2/sites-enabled/VHOST2.conf:1)
         port 80 namevhost VHOST3.domain.org (/etc/apache2/sites-enabled/VHOST3.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: 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

这一直运行良好,所以我们的组织认为这是不可接受的。;)

我们不允许网站返回 403 或 404 错误。我可以设置重定向,将对丑陋主机名的请求发送到其中一个虚拟主机。但我真正想做的是让 Apache 根本不响应对主机名的任何请求。这可能吗?

答案1

我会尝试使用 301 永久移动,然后将其发送到您的“主”网站,无论它是什么。这比让服务器不做任何响应要容易得多。此外,您忘记了仅包含 IP 的查询,它们也会返回 404。

相关内容