我怎样才能configurationApache,以便它拒绝直接连接到IP地址( http://xxx.xxx.xxx.xxx ),而不是虚拟主机名称http://example.com ?
我的VirtualHostconfiguration:
ServerName example.com <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/ <Directory /var/www/> AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
你不能拒绝连接,因为直到客户端实际发送一个HTTP请求,服务器才知道用户试图用作它们的HTTP主机的主机名(或IP)。 TCP监听器始终绑定到IP地址。
HTTP错误响应可以接受吗?
<VirtualHost *:80> ServerName catchall <Location /> Order allow,deny Deny from all </Location> </VirtualHost> <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/ <Directory /var/www/> AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
你必须去低层,它只在我的脑海里,在防火墙链上有一个REQUEST HOSTvalidation检查和你有什么Apache,这将允许包被忽略或丢弃
一个干净的方式来处理这是一个重写规则如下
<If "%{HTTP_HOST} == 'xxxx'"> RewriteRule ^.*$ http://www.example.com/$1 [L] </If>