ubuntu - Apache2 虚拟主机缺少文档根目录

标签 ubuntu apache2 virtualhost a-records

先感谢您。

我只是按照 digitalocean 的教程:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts .
我完成了所有指令,但是当我开始测试配置并从我的 parking 域添加一条 A 记录时,比如说 example.com,我的 digitalocean vps 地址是 192.168.10.2。
在这个方案中,我添加了这 3 个具有 3 个不同 DocumentRoot 的虚拟主机:

  • /var/www/domainone.example.com/index.html
  • /var/www/domaintwo.example.com/index.html
  • /var/www/domainthree.example.com/index.html

  • 然后在我的 parking 域中添加 3 个不同的 A 记录,如下所示:
  • 名称:domainone.example.com 地址:192.168.10.2
  • 名称:domaintwo.example.com 地址:192.168.10.2
  • 名称:domainthree.example.com 地址:192.168.10.2

  • 当我执行时,它发生如下:
  • 网址 domainone.example.com 转到/var/www/ domainone.example.com /index.html
  • 网址 domaintwo.example.com 转到/var/www/ domaintwo.example.com /index.html
  • 但是这个网址 domainthree.example.com 转到/var/www/ domaintwo.example.com /index.html

  • 我确定我在/etc/apache2/sites-available/(for each domain).config 处写了一个正确的 documentRoot 并重新启动 apache2 服务

    再次感谢你

    编辑
  • 这是用于/etc/apache2/sites-available/domaintwo.example.com.conf
    <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
    
        ServerAdmin localhost@admin
        DocumentRoot /var/www/domaintwo.example.com/public
        ServerName domaintwo.example.com
        ServerAlias www.domaintwo.example.com
    
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        SSLEngine on
    

    SSLCertificateFile/etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile/etc/apache2/ssl/apache.key
  • 这是用于/etc/apache2/sites-available/domainthree.example.com.conf
        <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
    
        ServerAdmin localhost@admin
        DocumentRoot /var/www/domainthree.example.com/public
        ServerName domainthree.example.com
        ServerAlias www.domainthree.example.com
    
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        </VirtualHost>
    
  • 最佳答案

    这是 IMO 的 SSL 问题。域 2 按字母顺序排序高于 3(优先级)。 Apache 默认通过 HTTPS (SSL) 执行 domaintwo。所以域 3 的 VH 是错误的,或者没有为这两个协议(protocol)启用。
    我猜测或多或少。希望能帮助到你。

    关于ubuntu - Apache2 虚拟主机缺少文档根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934097/

    相关文章:

    ubuntu - 当我在 ubuntu 中执行 Heroku 命令 "ERROR: EOF"时出现错误 "heroku login"?

    ubuntu - cmake 在 ubuntu 18.10 中找不到 gtest 1.8

    regex - Apache 多重重写规则

    static - 使用WebPy作为静态HTTP内容服务器

    php - ubuntu 上的 Apache 2 服务器无法解析 html 文件中的 php 代码

    matlab - 从终端运行 Octave 脚本时如何隐藏绘图输出?

    ubuntu - 如何为不同的 HTML URL 路径生成单独的日志?

    linux - Apache 如何访问 root 用户创建的 SSL 证书?

    apache - 将 mod_reqtimeout 设置为特定文件夹的无限时间

    apache - 配置虚拟主机和本地主机重定向到 xampp 文件夹