AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1168128
Accepted
Ruwenzori
Ruwenzori
Asked: 2019-08-25 01:05:46 +0800 CST2019-08-25 01:05:46 +0800 CST 2019-08-25 01:05:46 +0800 CST

Ubuntu 19.04 的虚拟主机

  • 772

我已经阅读了几篇文章并梳理了 stackExchange,但无法解决问题。我有两个域名,我想为每个域名创建虚拟主机。我创建了单独的文件夹,在其中托管每个域的index.html。我还创建了一个 conf 文件,在/etc/apache2/sites-available下,文件如下:

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>

xxxx是公共 IP
example1和example2不是我正在使用的域,而只是虚拟域。

当我尝试在我的服务器上加载域时,服务器总是向我显示example1的索引文件。

我不知道该怎么做,虚拟主机似乎无法与两个域一起使用。

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

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

virtualhost
  • 2 2 个回答
  • 372 Views

2 个回答

  • Voted
  1. scuba_mike
    2019-08-25T01:17:46+08:002019-08-25T01:17:46+08:00

    如果您通过 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 和comfor example2。当您从浏览器访问 example2 时,它是否有日志?你也可以提供这些吗?

    • 0
  2. Best Answer
    Ruwenzori
    2019-09-10T13:56:34+08:002019-09-10T13:56:34+08:00

    好吧,在搜索和重建我的服务器之后,我终于找到了我的问题的答案。我实际上是将我的服务器 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。

    • 0

相关问题

  • 在不同的子域上同时运行 Apache 和 Tomcat?

  • 如何使用 VirtualBox 作为 SQLServer 主机?

  • VirtualHost 的自定义 php.ini

  • 无法让“默认”Apache VirtualHost 工作

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve