Apache 使用错误的默认虚拟主机

Apache 使用错误的默认虚拟主机

系统:Ubuntu 14.04 作为 VPS,Apache 2.4.7

我设置了几个虚拟主机,监听:80 和:443 端口。

如果我apache2ctl -S它在端口 80 上显示错误的虚拟主机作为默认主机。事实上,如果我浏览到http://default.com,我从另一个虚拟主机获取内容:Apache 指定为默认虚拟主机,但不应该是 (customer.com)。我的设置有什么问题?

我启用的网站是:

default.com customer.com

apache2ctl -S

    VirtualHost configuration:
    *:80  is a NameVirtualHost
             default server customer.com (/etc/apache2/sites-enabled/customer.com.conf:1)
             port 80 namevhost customer.com (/etc/apache2/sites-enabled/customer.com.conf:1)
             port 80 namevhost www.customer.com (/etc/apache2/sites-enabled/customer.com.conf:19)
             port 80 namevhost www.default.com (/etc/apache2/sites-enabled/default.com.conf:36)
             port 80 namevhost tools.default.com (/etc/apache2/sites-enabled/default.com.conf:41)
             port 80 namevhost phpmyadmin.default.com (/etc/apache2/sites-enabled/default.com.conf:57)

    *:443  is a NameVirtualHost
             default server default.com (/etc/apache2/sites-enabled/customer.com.conf:26)
             port 443 namevhost default.com (/etc/apache2/sites-enabled/customer.com.conf:26)
             port 443 namevhost default.com (/etc/apache2/sites-enabled/default.com.conf:1)
             port 443 namevhost www.default.com (/etc/apache2/sites-enabled/default.com.conf:31)
             port 443 namevhost default.com (/etc/apache2/sites-enabled/default.conf:26)

default.com 虚拟主机

    <VirtualHost *:443>
    ServerName default.com

    DocumentRoot /data/www/default.com/public
    <Directory /data/www/default.com/public>
        Require all granted
    </Directory>

    # SSL stuff ...

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/data/www/default.com/public/$1

</VirtualHost>

<VirtualHost *:443>
     ServerName www.default.com
     RedirectMatch (.*) https://default.com$1
</VirtualHost>

<VirtualHost *:80>
     ServerName www.default.com
     RedirectMatch (.*) https://default.com$1
</VirtualHost>

<VirtualHost *:80>
    ServerName tools.default.com

    DocumentRoot /data/www/default.com/subdomains/tools/public

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/data/www/default.com/subdomains/tools/public/$1

    <Directory /data/www/default.com/subdomains/tools/public>
        Require all granted
    </Directory>
    LogLevel error
</VirtualHost>

<VirtualHost *:80>
    ServerName phpmyadmin.default.com
    DocumentRoot /usr/share/phpmyadmin
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin/$1

    <Directory /usr/share/phpmyadmin>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Customer.com 虚拟主机

<VirtualHost *:80>
    ServerName customer.com

    DocumentRoot /data/www/customer.com/public
    <Directory /data/www/customer.com/public>
        Require all granted
    </Directory>

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/data/www/customer.com/public/$1

</VirtualHost>

<VirtualHost *:80>
     ServerName www.customer.com
     RedirectMatch (.*) http://customer.com$1
</VirtualHost>

答案1

您没有非 www default.com 的条目

这应该添加到 default.com 配置中:

<VirtualHost *:80>
     ServerName default.com
     RedirectMatch (.*) https://default.com$1
</VirtualHost>

相关内容