【问题标题】:Apache VirtualHost redirection from different subdomains来自不同子域的 Apache VirtualHost 重定向
【发布时间】:2018-10-06 07:34:21
【问题描述】:

我有一个 DO droplet (Ubuntu 18.04),我想在其上托管两个站点。假设液滴的 IP 为 101.1.1.1。现在我希望站点从另一台服务器(具有不同的 IP,比如说 104.1.1.1.)子域指向。假设 siteone.example.org 和 sitetwo.example.org。所以我按照指南设置我的 Apache VirtualHost,如下所示:

<VirtualHost *:80>
    ServerAdmin webmaster@example.org
    ServerName siteone.example.org
    ServerAlias www.siteone.example.org
    DocumentRoot /var/www/siteone/public_html

    <Directory /var/www/siteone/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

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

但是,当我在浏览器中按 siteone.example.org 时,我没有得到任何响应。我在两端都设置了 A 名称以指向 101.1.1.1。是不是我做错了什么?

【问题讨论】:

    标签: apache


    【解决方案1】:

    您想在同一台机器上拥有 2 个网站,每个网站都有一个 IP 地址?所以:

    • 在您的系统上配置两个 IP
    • 在 Listen 中设置两个 IP:80
    • 为每个 IP/域配置一个 VirtualHost

    像这样:

    Listen *.80
    
    <VirtualHost 101.1.1.1:80>
        ServerName siteone.example.org
        ServerAlias www.siteone.example.org
    
        ServerAdmin webmaster.example.org
    
        DocumentRoot "/var/www/siteone/public/html"
        <Directory /var/www/siteone/public_html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/siteone_error.log
        CustomLog ${APACHE_LOG_DIR}/siteone_access.log combined
    
    </VirtualHost>
    
    <VirtualHost 104.1.1.1:80>
        ServerName sitetwo.example.org
        ServerAlias www.sitetwo.example.org
    
        ServerAdmin webmaster.example.org
    
        DocumentRoot "/var/www/sitetwo/public/html"
        <Directory /var/www/sitetwo/public_html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/siteotwo_error.log
        CustomLog ${APACHE_LOG_DIR}/sitetwo_access.log combined
    
    </VirtualHost>
    

    在您的 DNS 中,配置:

    • 101.1.1.1 siteone.example.org www.siteone.example.org
    • 104.1.1.1 sitetwo.example.org www.sitetwo.example.org

    【讨论】:

      猜你喜欢
      • 2019-01-15
      • 2017-01-14
      • 1970-01-01
      • 2017-02-17
      • 2018-07-20
      • 1970-01-01
      • 2012-02-18
      • 2019-04-04
      • 2011-05-28
      相关资源
      最近更新 更多