运行多个虚拟主机

运行多个虚拟主机

我想在我的服务器上运行多个域名(目前只有两个)。我已经将两个名称服务器都更改为指向我的服务器。

在 apache2.conf 文件中,我启用了“包含的站点已启用”。

我的 ports.conf 文件如下所示

NameVirtualHost *:80
Listen 80
Listen 443

<VirtualHost xx.xx.xx.xx:443>
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/apache.pem
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

    ServerAdmin [email protected]
    ServerName firstDomain.com
    DocumentRoot /var/www/
    ErrorLog /var/log/error.log
    CustomLog /var/log/access.log combined
</VirtualHost>

这是我的主页的设置。

我的 httpd.conf 文件如下所示

ServerName firstDomain.com

<VirtualHost xx.xx.xx.xx:80>
ServerAdmin [email protected]
ServerName firstDomain.com
DocumentRoot /var/www/
ErrorLog /var/log/error.log
    CustomLog /var/log/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName secondDomain.com
    ServerAlias *.secondDomain.com
    DocumentRoot /home/user/www/secondDomain.com/htdocs
</VirtualHost>

Options -Indexes All FollowSymLinks MultiViews

最后但同样重要的是,“sites-avaiable”中的“secondDomain”文件

<VirtualHost secondDomain.com>
    ServerAdmin [email protected]
    ServerName  secondDomain.com

    # Indexes + Directory Root.
    DirectoryIndex index.html
    DocumentRoot /home/user/www/secondDomain/htdocs/

    # CGI Directory
    ScriptAlias /cgi-bin/ /home/user/www/seoncDomain/cgi-bin/
    <Location /cgi-bin>
            Options +ExecCGI
    </Location>


    # Logfiles
    ErrorLog  /home/user/www/secondDomain/logs/error.log
    CustomLog /home/user/www/secondDomain/logs/access.log combined
</VirtualHost>

每次我重新启动 apache 服务器时,我都会收到一条错误消息,提示 VirtualHosts xx.xx.xx.xx:80 与 VirtualHosts xx.xx.xx.xx:80 重叠。

当我调用 secondDomain.com 时,只弹出 firstDomain.com。看来映射是错误的。

apachectl -t 输出:

[warn] VirtualHost xx.xx.xx.xx:80 overlaps with VirtualHost xx.xx.xx.xx:80, the first has   precedence, perhaps you need a NameVirtualHost directive
Syntax OK

apache2ctl -S 输出:

[Wed Feb 29 02:05:17 2012] [warn] VirtualHost xx.xx.xx.xx:80 overlaps with VirtualHost xx.xx.xx.xx:80, the first has precedence, perhaps you need a NameVirtualHost directive
VirtualHost configuration:
127.0.0.1:*           secondDomain.com (/etc/apache2/sites-enabled/secondDomain.com:1)
xx.xx.xx.xx:443       firstDomain.com (/etc/apache2/ports.conf:12)
xx.xx.xx.xx:80        firstDomain.com (/etc/apache2/httpd.conf:3)
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
     default server secondDomain.com (/etc/apache2/httpd.conf:11)
     port 80 namevhost secondDomain.com (/etc/apache2/httpd.conf:11)
     port 80 namevhost firstDomain.com (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost firstDomain.com (/etc/apache2/apache2.conf:241)
     port 80 namevhost secondDomain.com (/etc/apache2/apache2.conf:249)
Syntax OK

Wordpress 是通过 apt-get 安装的。我在 /var/www/ 中有一个符号链接,它指向 /usr/share/wordpress,并在 /etc/apache2/sites-available 和 a2ensite 中激活。

答案1

您有一个NameVirtualHost指令,但您没有使用它。您在声明中指定了 IP 地址和/或主机名<VirtualHost>- 这不是您想要的。

改变:

<VirtualHost xx.xx.xx.xx:80>

<VirtualHost secondDomain.com>

两者都很简单:

<VirtualHost *:80>

答案2

您可以尝试下一步:

  1. 将 firstDomain.com 虚拟主机声明移至站点可用/firstDomain
  2. 从 httpd.conf 中删除所有内容(您可以尝试定义服务器名称apache2.conf
  3. 确保您已站点可用/firstDomain站点可用/secondDomain符号链接到已启用站点/firstDomain已启用站点/secondDomain分别。

相关内容