Apache2 虚拟主机无法正确识别

Apache2 虚拟主机无法正确识别

我有两个虚拟主机,但是 apache 似乎默认使用其中一个。

这是主持人#1:

<VirtualHost *>

        ServerName goiclub.com
        ServerAlias www.goiclub.com *.goiclub.com
        ServerAdmin webmaster@localhost

        DocumentRoot /home/casey/public_html/goiclub/public

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

        <Directory /home/casey/public_html/goiclub/public>
                DirectoryIndex index.php index.htm index.html
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>



        ErrorLog /home/casey/public_html/goiclub/log/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel debug

        CustomLog /home/casey/public_html/goiclub/log/access.log combined
        ServerSignature On

        Alias /doc/ /usr/share/doc/
        <Directory "/usr/share/doc/">
                Options Indexes MultiViews FollowSymLinks
                AllowOverride None
                Order deny,allow
                Deny from all
                Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>

</VirtualHost>

这是另一个虚拟主机:

<VirtualHost *>
ServerAdmin [email protected]
ServerName geticlub.com
ServerAlias www.geticlub.com *.geticlub.com

DirectoryIndex index.php
DocumentRoot /home/casey/public_html/geticlub/public

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

        <Directory /home/casey/public_html/geticlub/public>
                DirectoryIndex index.php index.htm index.html
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

LogLevel debug
ErrorLog /home/casey/public_html/geticlub/log/error.log
CustomLog /home/casey/public_html/geticlub/log/access.log combined
</VirtualHost>

无论我输入 goiclub.com 还是 geticlub.com,它都会返回“geticlub.com”vhost。有人知道为什么吗?

这也可能有帮助:

sudo apache2ctl -t -D DUMP_VHOSTS
apache2: Could not reliably determine the server's fully qualified domain name, using 50.56.118.158 for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:*                    geticlub.com (/etc/apache2/sites-enabled/geticlub.com:1)
*:*                    goiclub.com (/etc/apache2/sites-enabled/goiclub.com:1)

答案1

您需要设置 NameVirtualHost。

打开 ports.conf 并添加:(您也可以将其放在第一个上面<virtualHost>

NameVirtualHost *:80
Listen 80

您还可以使用 IP 地址代替通配符。

您的 vhost 格式必须与 NameVirtualHost 格式完全相同。

如果格式如下:

NameVirtualHost 1.2.3.4:8080

那么 vhost 应该是:

<VirtualHost 1.2.3.4:8080>

相关内容