Ubuntu 19.04 的虚拟主机

Ubuntu 19.04 的虚拟主机

我读了几篇文章,也浏览了 stackExchange,但还是没能解决这个问题。我有两个域名,我想为每个域名创建虚拟主机。我创建了单独的文件夹,用于托管索引.html为每个域创建了一个 conf 文件,位于/etc/apache2/站点可用文件如下:

NameVirtualHost x.x.x.x:80

<VirtualHost x.x.x.x: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 example1.org
        ServerAlias www.example1.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/org/public_html
        #Options +FollowSymlinks
        # 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
        #<Directory /var/www/html/org/public_html>
        # Options -Indexes +FollowSymLinks +MultiViews
        # AllowOverride All
        # Require all granted
        #</Directory>

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example1aorg-error.log
        CustomLog ${APACHE_LOG_DIR}/example1org-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
</VirtualHost>



<VirtualHost x.x.x.x: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 example2.com
        ServerAlias www.example2.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/com/public_html
        #Options +FollowSymlinks
        # 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
        #<Directory /var/www/html/com/public_html>
        # Options -Indexes +FollowSymLinks +MultiViews
        # AllowOverride All
        #</Directory>

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example2com-error.log
        CustomLog ${APACHE_LOG_DIR}/example2com-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
</VirtualHost>

xxxxx是公共 IP
示例1示例2不是我正在使用的域名,而只是虚拟域名。

当我尝试在服务器上加载域名时,服务器始终向我显示示例1

我不知道该怎么办,虚拟主机似乎无法与两个域名一起工作。

编辑:我仍然无法弄清楚,这是我的域名:www.asanteniafrica.com www.asanteniafrica.org

我想相信这与域名的 .org 和 .com 部分有关,我仍在研究。

答案1

如果您通过 apt 安装,则可能需要检查是否有默认配置。如果有,则应将其从列表中删除以禁用它sites-enabled

如果不查看 的example1.com配置,很难判断问题出在哪里。但如果设置得像example2.com,请确保DocumentRoot指向不同的目录。这很容易被忽视。

快速编辑:VirtualHosts 肯定适用于多个域。我目前正在使用三个域和几个子域运行它,所有域都使用 VirtualHost。不过 SSL 很棘手...但这不是主题。

+++

提供配置后进行额外的编辑example1.com

如果没有注释,你的配置看起来是这样的:

NameVirtualHost x.x.x.x:80

<VirtualHost x.x.x.x:80>
        ServerName example1.org
        ServerAlias www.example1.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/org/public_html

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example1aorg-error.log
        CustomLog ${APACHE_LOG_DIR}/example1org-access.log combined
</VirtualHost>



<VirtualHost x.x.x.x:80>
        ServerName example2.com
        ServerAlias www.example2.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/com/public_html

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example2com-error.log
        CustomLog ${APACHE_LOG_DIR}/example2com-access.log combined
</VirtualHost>

除了域名之外,它们之间的区别在于orgexample1 和comexample2。当您从浏览器访问 example2 时,它是否有日志?您也可以提供这些日志吗?

答案2

好吧,在搜索和重建服务器后,我终于找到了问题的答案。我实际上是将服务器 IP 转发到我的域,而不是配置 DNS。我的域名是从 GoDaddy 购买的,我的服务器在 Linode。我按照以下说明配置我的 DNS。

https://www.linode.com/docs/platform/manager/dns-manager/

然后,登录 Godaddy.com 并使用以下指南将名称服务器添加到我的域:

https://www.godaddy.com/help/set-nameservers-for-domains-hosted-and-registered-with-godaddy-12316

一旦我更新了名称服务器,URL 需要大约 48 小时才能通过浏览器指向正确的 webroot。

相关内容