apache - httpd 使用 SSL 和子域/虚拟主机重定向

标签 apache redirect ssl https

我正在尝试在我的网站上设置 http -> https 重定向子域,该子域由 Apache(版本:2.2.31)提供服务。我为我的主站点 ( www.domain.com ) 购买了一个正确安装的通配符 SSL 证书,因为我的地址旁边有一个绿色的锁,所以应该完成这一部分。

问题:浏览到 subdomain.domain.com重定向到 www.domain.com我不知道为什么。我一直在阅读和关注 this页面以及其他几个具有类似内容的页面,但我遗漏了关键要素。

主站点由 /var/www/html 提供服务子域由 /var/www/vhosts/subdomain 提供服务.另外,我收到此错误:

[warn] _default_ VirtualHost overlap on port 443, the first has precedence

这是 /etc/httpd/conf/httpd.conf 的 vhost 部分:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName  www.domain.com
    ServerAlias www.domain.com
    #Redirect permanent / https://www.domain.com
    Redirect 302 / https://www.domain.com
</VirtualHost>

<VirtualHost *:80>
    ServerName  subdomain.domain.com
    ServerAlias subdomain.domain.com
    #Redirect permanent / https://subdomain.domain.com
    Redirect 302 / https://subdomain.domain.com
</VirtualHost>

这里是 /etc/httpd/conf.d/ssl.conf :

<VirtualHost *:443>
    ServerName  www.domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html
    ...
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLCertificateFile        /path/to/cert
    SSLCertificateKeyFile     /path/to/key
    SSLCertificateChainFile   /path/to/bundle
</VirtualHost>

<VirtualHost *:443>
    ServerName  subdomain.domain.com
    ServerAlias subdomain.domain.com
    DocumentRoot /var/www/vhosts/subdomain
    ...
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLCertificateFile        /path/to/cert
    SSLCertificateKeyFile     /path/to/key
    SSLCertificateChainFile   /path/to/bundle
</VirtualHost>

这里是 apachectl -S输出(我的域名被编辑/替换):

enter image description here

如有任何帮助,我们将不胜感激。

============================================= ========================

编辑:我删除了永久一词,清除了缓存,但问题仍然存在。好像跟警告有关吧?

此外,无论使用哪个 subdomain,我都会得到成功的响应即使它不存在,我也会使用。我可以为 subdomain 输入任何我想要的内容它会转到主站点。 http://<anything>.domain.comhttps://<anything>.domain.com都使用 https 加载主站点。

最佳答案

问题很简单,但难以捉摸,至少对我来说是这样。在 /etc/httpd/conf.d/ssl.conf 中,我需要添加以下行以使 VirtualHost 配置不同:

NameVirtualHost *:443

现在一切正常。

关于apache - httpd 使用 SSL 和子域/虚拟主机重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32194522/

相关文章:

具有 SNI 的 Apache HTTPS 反向代理,代理上没有 key

.htaccess 将目录重定向到单个页面

google-chrome - Chrome - 注册表中的证书设置

ssl - 将 .pem 转换为 .crt 和 .key

linux - 子域名指向linux中的一个文件夹

apache - 如何使用 Apache Rewrite 将用户重定向到完全限定的域名?

apache - 在 Apache 服务器上安装 cakephp 时未找到 cakephp/app/wwwroot/

php - 我应该使用什么 HTTP 重定向状态来链接异地?

linux - 命令输出重定向到文件和终端

asp.net - WCF SSL 无法为具有权限的 SSL/TLS 建立安全通道