apache 下多个域名多个目录 怎么配置 SSL

2016-11-21 00:22:35 +08:00
 jdle
我同服务器有 3 个域名, 3 个网站: A 、 B 、 C
配置 SSL 之后,第二个域名的 SSL 跳转老是跳转到第一个网站去。

假如:
在配置文件中,上下顺序为: A-B-C
那么 A 和 C 网站的 SSL 都正常,但是 B 不正常,访问 B 网站就说配置错误,显示了 A 网站的证书文件,就会跳转到 A 网站去。

如果我把域名配置文件换个位置,还是这样。换成: A-C-B ,
那么 A 和 B 网站又正常,但是 C 网又的 SSL 证书也显示 A 域名的了。
我在.htaccess 301 强制跳转到 https 也一样,反正谁在中间,谁就错误。
开始以为配置文件的路径用了 A 网站的,但是怎么看都是没有错的。

在 httpd.conf 的大概配置是:
<VirtualHost *:80>
DocumentRoot /www/A
ServerName A 域名
<Directory "/www/A">
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /www/A
SSLEngine on
证书路径
</VirtualHost>
--------------------------
<VirtualHost *:80>
DocumentRoot /www/B
ServerName B 域名
<Directory "/www/B">
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /www/B
SSLEngine on
证书路径
</VirtualHost>
---------------------------
<VirtualHost *:80>
DocumentRoot /www/C
ServerName C 域名
<Directory "/www/C">
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /www/C
SSLEngine on
证书路径
</VirtualHost>
-------------------------
在.htaccess 做过 301 跳转是:
RewriteEngine On
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
------------------------------------------
和这种(不过这样配置网站直接不能访问了)
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
这种是看的通天塔家的方法, SSL 他家买的。。。
4084 次点击
所在节点    SSL
2 条回复
jdle
2016-11-21 00:24:05 +08:00
怎么发布出来之后 。。。这么乱
shiji
2016-11-21 06:10:32 +08:00
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这是我用的,把这个放在每个 80 端口的 VirtualHost 里面,重启 apache 试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/321952

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX