V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Mayuri
V2EX  ›  问与答

http 与 https 所指向的站点目录不同?

  •  
  •   Mayuri · 2018-11-08 01:30:25 +08:00 · 2738 次点击
    这是一个创建于 1968 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近倒腾一个 VPS 却出现了子域名 a.aa.com 通过 HTTPS 却转到了 aa.com 站点目录 的神奇现象,这几天都在纠结这个问题

    • LAMP 环境已安装
    • Let's Encrypt 通配符证书已申请配置完毕
    • httpd-vhosts.conf 已经添加了子域名
    • Vhost 目录下的 a.aa.com.conf 已经配置了 443 端口转到子域名的目录

    求各位大神解决我的疑惑。。。百度谷歌了一圈都无果

    第 1 条附言  ·  2018-11-08 12:54:14 +08:00

    Apache 是用 lnmp1.5 一键安装包配置的

    vhost 里的 a.example.com.conf 配置如下

    <VirtualHost *:80>
    ServerAdmin [email protected]
    php_admin_value open_basedir "/var/www/html/a:/tmp/:/var/tmp/:/proc/"
    DocumentRoot "/var/www/html/a"
    ServerNamen a.example.com
    ErrorLog "/home/wwwlogs/a.example.com-error_log"
    CustomLog "/home/wwwlogs/a.example.com-access_log" combined
    <Directory "/var/www/html/a">
        SetOutputFilter DEFLATE
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        DirectoryIndex index.html index.php
    </Directory>
    </VirtualHost>
    
    <VirtualHost *:443>
    ServerAdmin [email protected]
    php_admin_value open_basedir "/var/www/html/a:/tmp/:/var/tmp/:/proc/"
    DocumentRoot /var/www/html/a
    ServerName a.example.com:443
    ErrorLog "/home/wwwlogs/a.example.com-error_log"
    CustomLog "/home/wwwlogs/a.example.com-access_log" combined
    SSLEngine on
    SSLCertificateFile /usr/local/apache/conf/ssl/a.example.com/a.example.com.cer
    SSLCertificateKeyFile /usr/local/apache/conf/ssl/a.example.com/a.example.com.key
    SSLCertificateChainFile /usr/local/apache/conf/ssl/a.example.com/ca.cer
    Protocols h2 h2c http/1.1
    <Directory "/var/www/html/a">
        SetOutputFilter DEFLATE
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        DirectoryIndex index.html index.php
    </Directory>
    </VirtualHost>
    
    16 条回复    2018-11-08 20:23:25 +08:00
    also24
        1
    also24  
       2018-11-08 02:11:46 +08:00
    先贴个配置出来嘛~
    xmlf
        2
    xmlf  
       2018-11-08 07:38:11 +08:00 via Android
    我最近也遇到这样奇怪的事
    PressOne
        3
    PressOne  
       2018-11-08 08:24:55 +08:00 via Android
    应该是证书的问题,是免费的证书吗?
    Vhc
        4
    Vhc  
       2018-11-08 08:41:31 +08:00
    我这边访问 a.aa.com 并未自动跳转到 aa.com
    楼主电脑中毒了吧?
    Mayuri
        5
    Mayuri  
    OP
       2018-11-08 09:01:09 +08:00
    @also24 aa.com 不太好看 我换成 example.com 。。
    ```httpd-vhost.conf ``` 配置如下
    ```
    <VirtualHost *:80>
    ServerAdmin [email protected]
    #php_admin_value open_basedir "/var/www/html/a:/tmp/:/var/tmp/:/proc/"
    DocumentRoot "/var/www/html/a"
    ServerName a.example.com
    ErrorLog "/home/wwwlogs/a.example.com-error_log"
    CustomLog "/home/wwwlogs/a.example.com-access_log" combined
    <Directory "/var/www/html/a">
    SetOutputFilter DEFLATE
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    DirectoryIndex index.html index.php
    </Directory>
    </VirtualHost>

    <VirtualHost *:80>
    ServerAdmin [email protected]
    #php_admin_value open_basedir "/home/wwwroot/example.com:/tmp/:/var/tmp/:/proc/"
    DocumentRoot "/home/wwwroot/example.com"
    ServerName example.com
    ErrorLog "/home/wwwlogs/example.com-error_log"
    CustomLog "/home/wwwlogs/example.com-access_log" combined
    <Directory "/home/wwwroot/example.com">
    SetOutputFilter DEFLATE
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    DirectoryIndex index.html index.php
    </Directory>
    </VirtualHost>
    ```
    Mayuri
        6
    Mayuri  
    OP
       2018-11-08 09:02:11 +08:00
    @Vhc 并不是电脑中毒了。。在手机上,别的电脑上访问也是如此,各种浏览器也是如此
    Mayuri
        7
    Mayuri  
    OP
       2018-11-08 09:02:37 +08:00
    @PressOne 是的,Let's Encrypt 免费证书
    imdong
        8
    imdong  
       2018-11-08 09:10:25 +08:00   ❤️ 1
    http 和 https 对 nginx 来说 其实可以是两个不同的网站。
    所以,检查下 nginx 和 apache 里面 https 和 http 对应的目录是否是同一个吧。
    apache 不是很懂。
    配置没看到 https 的配置啊,等熟悉 apache 的人来吧。
    你贴的事两个网站?
    Mayuri
        9
    Mayuri  
    OP
       2018-11-08 12:58:52 +08:00
    @imdong 嗯,也不知道是配置哪里出现了错误,继续等待大神
    不能在每个回复发外链也不能插图。。一个是主域名另一个是子域名
    Mayuri
        10
    Mayuri  
    OP
       2018-11-08 19:30:02 +08:00 via Android
    @imdong @also24 @xmlf @PressOne @Vhc 问题总算解决了,只要将 vhost 下的 a.example.com.conf 文件内<VirtualHost *:443>的内容复制到 httpd-vhosts.conf 里面再重启 Apache 便行了,证书也正常😄 同时也奇怪为什么之前的配置不能够起作用。。
    Vhc
        11
    Vhc  
       2018-11-08 19:32:54 +08:00
    @Mayuri #10 恭喜。我只会用 nginx,看不懂 apache 的配置文件,所以之前没有能帮到你
    Vhc
        12
    Vhc  
       2018-11-08 19:38:34 +08:00
    @Mayuri #10 话说,你犯这种常识性的错误是很不应该的

    拿 nginx 举例说吧,你应该检查 httpd-vhosts.conf 文件里是否有这么一行代码 include /etc/apache/vhost/*.conf;
    Mayuri
        13
    Mayuri  
    OP
       2018-11-08 19:57:01 +08:00 via Android
    @Vhc 没事,我也很久没在网上提问过,能回复我便很高兴了
    Mayuri
        14
    Mayuri  
    OP
       2018-11-08 19:59:51 +08:00 via Android
    @Vhc 然而 Apache 里的 httpd.conf 里面有一句 IncludeOptional conf/vhost/*.conf。。
    Mutoo
        15
    Mutoo  
       2018-11-08 20:02:42 +08:00
    80 配置里的 ServerName 写成 ServerNamen 了。
    Mayuri
        16
    Mayuri  
    OP
       2018-11-08 20:23:25 +08:00 via Android
    @Mutoo 抱歉抱歉,那里是我改错了,原配置是 ServeName,如果是 ServeNamen 的话。。那 http 也会访问不了吧。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2449 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:54 · PVG 23:54 · LAX 08:54 · JFK 11:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.