我一直有一些问题,build立我的Apache Web服务器,只通过HTTPS提供页面。 我想这个星期早些时候我已经钉了它,但经过一番修改之后,似乎我又把它弄坏了,我不知道我到底什么时候把它弄坏了。
我的设置产生这个输出,因此我的configuration语法应该是可以的:
# apache2ctl -t -D DUMP_VHOSTS VirtualHost configuration: 192.168.0.1:80 is a NameVirtualHost default server cal.example.com (/etc/apache2/sites-enabled/99-davical:2) port 80 namevhost cal.example.com (/etc/apache2/sites-enabled/99-davical:2) port 80 namevhost proius.example.com (/etc/apache2/sites-enabled/proius:1) port 80 namevhost slnew.example.com (/etc/apache2/sites-enabled/slnew:1) port 80 namevhost webmail.example.com (/etc/apache2/sites-enabled/webmail:1) 192.168.0.1:443 is a NameVirtualHost default server proius.example.com (/etc/apache2/sites-enabled/proius:10) port 443 namevhost proius.example.com (/etc/apache2/sites-enabled/proius:10) port 443 namevhost slnew.example.com (/etc/apache2/sites-enabled/slnew:10) port 443 namevhost webmail.example.com (/etc/apache2/sites-enabled/webmail:10) 192.168.0.1:8443 is a NameVirtualHost default server cal.example.com (/etc/apache2/sites-enabled/99-davical:11) port 8443 namevhost cal.example.com (/etc/apache2/sites-enabled/99-davical:11) Syntax OK
这就是我所有的虚拟主机的定义:
<VirtualHost slnew.example.com:80> ServerName slnew.example.com ServerAdmin [email protected] DocumentRoot /var/www/slnew RewriteEngine On RewriteLogLevel 0 RewriteRule ^/(.*) https://slnew.example.com:443/$1 [L,R] </VirtualHost> <VirtualHost slnew.example.com:443> ServerName slnew.example.com ServerAdmin [email protected] DocumentRoot /var/www/slnew <Directory /var/www/slnew> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> LogLevel info ErrorLog ${APACHE_LOG_DIR}/slnew_error.log CustomLog ${APACHE_LOG_DIR}/slnew_access.log combined SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key SSLProtocol -all +SSLv3 +TLSv1 SSLCipherSuite SSLv3:+HIGH:+MEDIUM <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-6]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown </VirtualHost>
当我访问我的网站时,我在Google Chrome中遇到这个错误:
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
您不能在同一IP:端口组合上运行多个基于SSL名称的虚拟主机。
Apache无法知道你想要哪一个,因为Host:头部在安全通道build立之前不会被发送,并且build立安全通道,Apache必须select一个证书来使用。 这是一个鸡与鸡蛋的问题。
但除此之外,您正试图通过SSL连接访问HTTP内容,这会产生您报告的错误。 这是与证书一个不同的问题。
规则#0:不,EVER,在虚拟主机定义中使用主机名。 永远。
规则1:别的时候不要使用重写。
在将HTTPredirect到HTTPS的情况下,您可以创build与SSL虚拟主机一样多的HTTP(端口80)虚拟主机,然后redirect到每个SSL的版本。
你似乎已经实现了80%,然后放弃了,并认为使用重写是一个合适的解决scheme:)
相反,将上面的所有replace为:
<VirtualHost *:80> ServerName slnew.example.com Redirect Permanent / https://slnew.example.com/ </Virtualhost>
现在,SSL部分至less会停止导致错误,但是您将为每个不是所选证书的规范CN的SSL虚拟主机提供证书警告(apache将始终select在第一个 SSL虚拟主机中定义的证书)。
如果你真的想要这个工作正常,每个虚拟主机都需要有自己的IP,在虚拟主机定义中使用:
<Virtualhost 55.66.77.88:443> ServerName slnew.example.com
等等