【问题标题】:Setup subdomain in Apache server ubuntu 16.04 lts在 Apache 服务器 ubuntu 16.04 lts 中设置子域
【发布时间】:2017-06-26 17:09:11
【问题描述】:

如何在 ubuntu 服务器上的 Apache 中设置子域。

我的 apache.conf 文件:

<VirtualHost *:80>
        ServerName www.hello.com
        DocumentRoot /var/www/html/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:81>
        ServerName bye.hello.com
        DocumentRoot /var/www/html/other
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

现在我通过 IP 访问:10.20.20.34:80 (www.hello.com) 和 10.20.20.34:81 (bye.hello.com)。 80 端口很好用,但我无法为 81 端口设置子域。

我们不需要公共访问,一切都在 Intranet 上。我们修改了路由器中的 DNS 记录。

重要提示:我必须同时保留访问权限:10.20.20.34:81 和 bye.hello.com

以下是所发生情况的摘要:

  • 10.20.20.34:80 - 好的。
  • 10.20.20.34:81 - 好的。
  • www.hello.com - 好的。
  • bye.hello.com - 失败,请显示 www.hello.com

【问题讨论】:

    标签: apache .htaccess ubuntu dns subdomain


    【解决方案1】:

    您需要将listen directive 添加到您的/etc/apache2/ports.conf。在该文件中,您将看到:

    Listen 80
    

    在下面添加第二行:

    Listen 80
    Listen 81
    

    然后重启Apache:

    apache2ctl restart
    

    否则,我认为您的虚拟主机设置没有任何问题。

    更新

    Apache 不会通过 DNS 为您执行此操作。您可以阅读this 了解更多信息。您最好将第二个虚拟主机指令更改为:

    <VirtualHost *:80>
            ServerName bye.hello.com
    

    它应该可以正常工作。使用两个端口没有任何优势。如果您有架构限制,那么上面的链接有一些高级解决方案。

    【讨论】:

    • 我有这个。 10.20.20.34:80 - 好的。 10.20.20.34:81-好的。 www.hello.com - 好的。 bye.hello.com - 失败,给我看看 www.hello.com
    • 那么当您尝试 bye.hello.com 时会发生什么? 404?你检查过 /var/log/apache2/error.log 了吗?
    • @JuanPabloLarrea 很高兴听到这个消息!
    猜你喜欢
    • 2018-08-18
    • 2017-01-10
    • 2018-10-19
    • 1970-01-01
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多