Ubuntu

Apache2(Ubuntu 16.04)子域顯示主網站而不是子域網站

  • May 8, 2018

預設.conf

<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.conf

<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>

如果我刪除主站點,它會完美地載入子域。如果啟用了主站點,則子域會載入主站點。載入我的意思是它不會重定向,它只是載入主站點目錄。

<VirtualHost *:80>它們相互獨立<VirtualHost *:443>且不繼承任何配置。您的兩個 HTTPS 虛擬主機都缺少該ServerName指令;第一個匹配顯示為預設網站。

引用自:https://serverfault.com/questions/911168