两个域(当SSL)在同一个目录下

我的apache2configuration是有问题的:我有一个服务器上的两个网站:

  • domain1.tdl
  • domain2.tdl

其中一个(domain2.tdl)必须是,并且可以通过端口443访问(使用SSL)。 所有的域必须是和可以通过端口80访问。但是,当我们尝试访问端口443上的domain1.tdl显示domain2.tdl文件。 因此,在端口443上,可以通过domain1.tdl domain2.tdl访问domain2.tdl。 我不想要它!

我的configuration:

domain1.tdl

<VirtualHost *:80> DocumentRoot /home/sites/domain1.tdl/www ServerName domain1.tdl ServerAlias www.domain1.tdl ServerAdmin [email protected] RewriteEngine on <Directory "/home/sites/domain1.tdl/www"> AllowOverride All allow from all Options -Indexes </Directory> </VirtualHost> <VirtualHost *:443> DocumentRoot /home/sites/domain1.tdl/www ServerName domain1.tdl ServerAlias www.domain1.tdl ServerAdmin [email protected] RewriteEngine on <Directory "/home/sites/domain1.tdl/www"> AllowOverride All allow from all Options -Indexes </Directory> 

domain2.tdl

 <VirtualHost *:80> DocumentRoot "/home/sites/domain2.tdl/web" ServerName domain2.tdl ErrorLog /var/log/apache2/site/error_domain2.tdl.log CustomLog /var/log/apache2/site/access_domain2.tdl.log combined <Directory "/home/sites/domain2.tdl/web"> allow from all Options -Indexes </Directory> ServerAlias www.domain2.tdl </VirtualHost> <VirtualHost domain2.tdl:443> DocumentRoot "/home/sites/domain2.tdl/web" ServerName domain2.tdl ErrorLog /var/log/apache2/site/error_domain2.tdl.log CustomLog /var/log/apache2/site/access_domain2.tdl.log combined SSLEngine on SSLCertificateFile /etc/ssl/private/domain2.tdl/domain2.tdl.crt SSLCertificateKeyFile /etc/ssl/private/domain2.tdl/domain2.tdl.key SSLCACertificateFile /etc/ssl/private/domain2.tdl/GandiStandardSSLCA.pem SSLVerifyClient None <Directory "/home/sites/domain2.tdl/web"> allow from all Options -Indexes </Directory> ServerAlias www.domain2.tdl </VirtualHost> 

说明

当您使用NameVirtualHosts时,Apache将使用Host:头中给出的主机名来确定您应该访问哪个虚拟主机。 SSL历史上一直存在问题 – 由于整个会话都是encryption的, 包括 Host:头,因此Apache需要先解密会话,才能确定要使用哪个虚拟主机。 但是解密所需的信息是在一个VirtualHost部分中,创build一个catch 22 – apache需要一个VirtualHost,但是它不知道哪一个,所以它会select它find的第一个。

SSL最近的实现包括SNI,它可以使主机名不encryption。 但是为了达到这个目的,服务器和客户端都需要运行相当新的SSL版本,并且尽pipe可以控制服务器,但是通常无法控制客户端。

首先,由于您不希望domain1.tdl通过SSL可达,您可以简单地删除domain1的VirtualHost:443部分。 (这不会解决当前的问题,但是如果你不想使用它,你不应该保留configuration;在某些情况下导致你的问题!

其次,您需要创build一些方法来在SSL协商之后检查正确的主机名,并且只允许通信到正确的主机名。 最简单的方法是使用mod_rewrite并进行标题检查,并拒绝没有正确主机名的所有通信。 这是一个例子:

 RewriteEngine On # to turn rewriting on RewriteCond %{HTTP_HOST} ^(www.)?domain2.tdl # If http_host doesn't match (www.)domain2.tdl RewriteRule (.*) http://%{HTTP_HOST}/$1 # then redirect to http for the hostname that was used, keeping the path intact 

如果您希望只是让他们知道不允许访问,则可以发出错误消息:

 RewriteEngine On # to turn rewriting on RewriteCond %{HTTP_HOST} ^(www.)?domain2.tdl # If http_host doesn't match (www.)domain2.tdl RewriteRule (.*) - [F] # then issue a "403 Forbidden" error page 

这些命令应该位于domain2.tdl:443的VirtualHost指令中。