我正在尝试将两个版本的Domain-A(HTTP和HTTP)重定向到另一个域Domain-B。很简单的东西,但不是那么简单。
看看我现在正在做什么:
<VirtualHost *:80>
ServerName DOMAIN-A.com
ServerAlias www.DOMAIN-A.com
RewriteEngine on
RewriteRule (.*) http://DOMAIN-B.com? [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName DOMAIN-A.com
ServerAlias www.DOMAIN-A.com
RewriteEngine on
RewriteRule (.*) https://DOMAIN-B.com? [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName DOMAIN-B.com
DocumentRoot /var/www/DOMAIN-B/html
SSLEngine on
SSLCertificateFile "/etc/letsencrypt/live/DOMAIN-B/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/DOMAIN-B/privkey.pem"
SSLCertificateChainFile "/etc/letsencrypt/live/DOMAIN-B/chain.pem"
</VirtualHost>
按预期将HTTP(端口80)DOMAIN-A请求发送到DOMAIN-B
对HTTPS(端口443)DOMAIN-A的请求不会重定向,而是给我SSL证书错误。由于DOMAIN-A没有SSL,因此我显示的是默认服务器证书,而不是重定向。 (SSL错误域)当我在浏览器中接受异常时,它将重定向。
问题***
您可以在我的vhost文件上看到任何错误吗?还是需要为要重定向的域创建SSL证书?任何更简单的解决方法?
非常感谢
答案 0 :(得分:1)
您必须在端口443上包含DOMAIN-A.com的SSL文件,如下所示:
<VirtualHost *:80>
ServerName DOMAIN-A.com
ServerAlias www.DOMAIN-A.com
Redirect permanent / https://DOMAIN-B.com/
</VirtualHost>
<VirtualHost *:443>
ServerName DOMAIN-A.com
ServerAlias www.DOMAIN-A.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/DOMAIN-A/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/DOMAIN-A/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/DOMAIN-A/chain.pem
Redirect permanent / https://DOMAIN-B.com/
</VirtualHost>
<VirtualHost *:443>
ServerName DOMAIN-B.com
DocumentRoot /var/www/DOMAIN-B/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/DOMAIN-B/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/DOMAIN-B/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/DOMAIN-B/chain.pem
</VirtualHost>
此外,您在DOMAIN-A.com中有一个小错误,该错误已重定向到http://DONMAIN-B.com/
,但是在端口80上没有该域的配置。也许您也应该添加此域。