Apache2(Ubuntu 16.04)子域名显示主网站而不是子域名网站

Apache2(Ubuntu 16.04)子域名显示主网站而不是子域名网站

默认配置文件

<VirtualHost *:80>
    DocumentRoot /var/www/example
    ServerName example.com
    DirectoryIndex index.php index.html
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/subdomain
    ServerName subdomain.example.com
    DirectoryIndex index.php index.html
</VirtualHost>

默认 SSL 配置文件

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        DocumentRoot /var/www/example/public
        SSLEngine on
        SSLCertificateFile      /var/www/Origin.crt
        SSLCertificateKeyFile   /var/www/Key.key

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>

        # BrowserMatch "MSIE [2-6]" \
        #               nokeepalive ssl-unclean-shutdown \
        #               downgrade-1.0 force-response-1.0
    </VirtualHost>

    <VirtualHost *:443>
        DocumentRoot /var/www/subdomain/public
        SSLEngine on
        SSLCertificateFile      /var/www/Origin.crt
        SSLCertificateKeyFile   /var/www/Key.key

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>

        # BrowserMatch "MSIE [2-6]" \
        #               nokeepalive ssl-unclean-shutdown \
        #               downgrade-1.0 force-response-1.0
    </VirtualHost>
</IfModule>

如果我删除主站点,它会完美地加载子域名。如果启用了主站点,子域名会加载主站点。加载的意思是它不会重定向,只会加载主站点目录。

答案1

它们彼此<VirtualHost *:80>独立<VirtualHost *:443>,不会继承任何配置。您的两个 HTTPS 虚拟主机都缺少ServerName指令;第一个匹配项显示为默认网站。

相关内容