Apache:多个站点,但没有redirect

请原谅这是一个初学者的问题,但我急需一些build议。

我想运行两个网站,说foo.orgbar.info ,在同一台服务器上。 两者都应该可以通过http和https访问。 我的目录/etc/apache2/sites-enabled包含文件foobar

这两个文件看起来像这样(省略一些日志logging):

FOO

 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.foo.org DocumentRoot /var/www/dir ServerAlias foo.org foo.de www.foo.de RewriteEngine On RewriteOptions inherit </VirtualHost> <VirtualHost *:443> ServerAdmin [email protected] ServerName www.foo.org DocumentRoot /var/www/dir ServerAlias www.foo.de RewriteEngine On RewriteOptions inherit # # SSL Specific options SSLEngine on SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key </VirtualHost> 

酒吧

 <VirtualHost *:80> ServerAdmin [email protected] ServerName blog.bar.info DocumentRoot /var/www/bar/blog ServerAlias www.blog.bar.info RewriteEngine On RewriteOptions inherit </VirtualHost> <VirtualHost *:80> ServerAdmin [email protected] ServerName analytics.bar.info DocumentRoot /var/www/bar/analytics # ServerAlias RewriteEngine On RewriteOptions inherit </VirtualHost> <VirtualHost *:443> ServerAdmin [email protected] ServerName blog.bar.info DocumentRoot /var/www/bar/blog RewriteEngine On RewriteOptions inherit # # SSL Specific options SSLEngine on SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key </VirtualHost> 

主要问题是,当访问https://foo.org时 ,它现在被redirect到https://blog.bar.info 。

与http,它似乎工作正常。

我的错误是什么? 另外:我怎样才能确保一个网站永远不会redirect到另一个?

编辑: ports.conf文件包含:

 # If you just change the port or add more ports here, you will likely also # have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default # This is also true if you have upgraded from before 2.2.9-3 (ie from # Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and # README.Debian.gz NameVirtualHost *:80 Listen 80 <IfModule mod_ssl.c> # If you add NameVirtualHost *:443 here, you will also have to change # the VirtualHost statement in /etc/apache2/sites-available/default-ssl # to <VirtualHost *:443> # Server Name Indication for SSL named virtual hosts is currently not # supported by MSIE on Windows XP. Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule> 

当你说“redirect”时,你的意思是在没有客户端浏览器中的URL改变的情况下提供错误的内容,是正确的? 我的猜测是你的configuration中没有NameVirtualHost *:443指令 – 在Debian的configuration结构中,这应该在ports.conf

不过,要小心这个设置。 仅使用自签名的SSL证书运行就可以进行testing,但是如果在向互联网开放时没有对其进行计算,则会导致问题。

您需要以下三件事情之一才能在暴露给公众的情况下正常运行:

  • 包含两个域的单个SSL证书。 这被称为SAN或UCC证书,花费两个以上的正规证书将覆盖两个不同的域。
  • 每个SSL站点的IP地址不同,每个都有自己的证书。
  • 保证所有访问您的站点的客户端浏览器都能够使用TLS SNI,这将允许您使用不同的证书在同一个IP地址上configuration每个站点。 在2014年Windows XP开始消失之前,不要在大多数公共站点上下注。

编辑:

要使客户端在尝试访问未configurationSSL <VirtualHost>的站点时出现错误,您需要修改443上的默认虚拟主机。

要加载的第一个<VirtualHost *:443>块承担“default”的angular色,为所有对与另一个<VirtualHost *:443>块中的ServerNameServerAlias不匹配的ServerName提出请求。 因此,让我们创build一个“默认”,只提供错误,而对其他configuration的网站的请求仍然得到正确的处理。

  • /etc/apache2/sites-available创build一个名为0-ssl-default或者类似于字母表中的类似内容,如下所示:

     <VirtualHost *:443> ServerName default-ssl-catch-all <Location /> Order allow,deny Deny from all </Location </VirtualHost> 
  • a2ensite 0-ssl-default启用,然后重新启动Apache。

在您的www.foo.org port 443configuration中,您需要configurationServerAlias以包含foo.org的条目

 ServerAlias foo.org foo.de www.foo.de