我的apache2配置有问题:我在服务器上有两个网站:
其中一个(domain2.tdl)必须并且可以在端口443 (使用SSL)上访问。所有域都必须并且可以通过端口80访问。但是,当我们试图访问端口443上的domain1.tdl时,将显示domain2.tdl文件。因此,在端口443上,domain2.tdl可以由domain1.tdl和domain2.tdl访问。我不想要!
我的配置:
<VirtualHost *:80>
DocumentRoot /home/sites/domain1.tdl/www
ServerName domain1.tdl
ServerAlias www.domain1.tdl
ServerAdmin xxx@mail.com
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 xxx@mail.com
RewriteEngine on
<Directory "/home/sites/domain1.tdl/www">
AllowOverride All
allow from all
Options -Indexes
</Directory><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>发布于 2013-05-14 10:51:22
当您使用NameVirtualHosts时,Apache将使用主机名称: header来确定您应该访问的虚拟主机中的哪一个。这在SSL中一直存在问题--因为整个会话都是加密的,包括主机:报头,Apache需要对会话进行解密,然后才能确定要使用哪个虚拟主机。但是解密所需的信息在VirtualHost部分中,创建了一个catch 22 -- apache需要一个VirtualHost,但它不知道是哪个,所以它会选择找到的第一个。
最近实现的SSL包括SNI,这使得不加密主机名成为可能。但是为了使其工作,服务器和客户端都需要运行较新版本的SSL,虽然您可以控制服务器,但通常无法控制客户端。
首先,由于您不希望通过SSL访问domain1.tdl,所以可以简单地删除domain1的VirtualHost:443部分。(这不能解决当前的问题,但是如果您不想使用它,就不应该一直使用配置;在某个时候,它会给您带来问题!)
第二,在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指令中。
https://serverfault.com/questions/507599
复制相似问题