Apache,vhost,redirect,https,ssl问题

问题:

  • https://www.example.com – >应redirect到http://www.example.com ,不,给出错误代码:ssl_error_rx_record_too_long不redirect,error_log:“[错误] [客户端127.0.1.3]无效的方法请求\ x16 \ x03 \ x01
  • https://www.example.com/fundprocess.html – >应redirecthttps://example.com/fundprocess.html ,给出错误代码:ssl_error_rx_record_too_long不redirect,error_log:“[error] [client 127.0.1.3] Invalid方法请求\ x16 \ x03 \ x01“
  • https://example.com – >应该redirect到http://www.example.com ,不
  • http://example.com/ – >应该redirect到http://www.example.com ,不
  • http://example.com/fundprocess.html应该redirect到https://example.com/fundprocess.html ,不

在重写日志中没有条目反对这些错误。

虚拟主机configuration

<VirtualHost 127.0.1.3:80> ServerAdmin [email protected] ServerName www.example.com DocumentRoot /var/www/html <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> Redirect permanent /fundprocess.html https://example.com/fundprocess.html Redirect permanent /fund_process.php https://example.com/fund_process.php ErrorLog /var/log/apache2/example.com-error_log TransferLog /var/log/apache2/example.com-access_log LogLevel warn RewriteLog /var/log/apache2/example.com-rewrite_log RewriteLogLevel 9 </VirtualHost> <VirtualHost 127.0.1.2:80> ServerAdmin [email protected] ServerName example.com DocumentRoot /var/www/html RewriteCond %{REQUEST_URI} !fundprocess.html [NC] RewriteCond %{REQUEST_URI} !fund_process.php [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteCond %{REQUEST_URI} fundprocess.html [NC] RewriteCond %{REQUEST_URI} fund_process.php [NC] RewriteRule (.*) https://example.com/$1 [R=301,L] </VirtualHost> <VirtualHost 127.0.1.3:443> ServerAdmin [email protected] ServerName www.example.com DocumentRoot /var/www/html RewriteCond %{REQUEST_URI} !fundprocess.html [NC] RewriteCond %{REQUEST_URI} !fund_process.php [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteCond %{REQUEST_URI} fundprocess.html [NC] RewriteCond %{REQUEST_URI} fund_process.php [NC] RewriteRule (.*) https://example.com/$1 [R=301,L] </VirtualHost> <VirtualHost 127.0.1.2:443> ServerAdmin [email protected] ServerName example.com DocumentRoot /var/www/html <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !fundprocess.html [NC] RewriteCond %{REQUEST_URI} !fund_process.php [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L] ErrorLog /var/log/apache2/example.com-ssl-error_log TransferLog /var/log/apache2/example.com-ssl-access_log LogLevel warn RewriteLog /var/log/apache2/example.com-rewrite_log RewriteLogLevel 9 SSLEngine On SSLCertificateFile /etc/certs/example.crt SSLCertificateKeyFile /etc/certs/example.key SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 </VirtualHost> 

这不是redirect的问题,这是SSL的问题(请求必须在redirect发生之前解密)。

你有没有在你的Apacheconfiguration中的任何地方Listen 443 ? 如果你不在Listen 80部分附近,请把它放在里面。 你在这个服务器上运行任何其他SSL网站? 确保他们没有使用相同的IP地址。 最后,如果你的SSL证书可以在其他地方使用,请尝试在这个网站上使用它 – 它会在浏览器中发出警告,但是如果你接受警告,它应该redirect – 那么你知道问题是你的SSL证书。

ssl_error_rx_record_too_long发生在Apache期望ssl并收到http时。

确保所有端口443请求都通过SSLEngine On进入虚拟主机。 您需要修复您的<VirtualHost 127.0.1.3:443>

此外,您的证书需要同时适用于example.com和* .example.com。 否则,您的客户将得到丑陋的警告,而不是redirect。