V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
jdle
V2EX  ›  SSL

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

  •  
  •   jdle · 2016-11-21 00:22:35 +08:00 · 4056 次点击
    这是一个创建于 2685 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我同服务器有 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 他家买的。。。
    jdle
        1
    jdle  
    OP
       2016-11-21 00:24:05 +08:00
    怎么发布出来之后 。。。这么乱
    shiji
        2
    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 试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   952 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:39 · PVG 05:39 · LAX 14:39 · JFK 17:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.