Ubuntu

Apache 2 / Ubuntu 14.04 上不正確的虛擬主機配置問題

  • August 7, 2020

我在我的 Digital Ocean Droplet 上成功設置了各種子域作為虛擬主機。但由於某種原因,我最新的子域服務於不同的子域,我不知道為什麼。所以如果你去selingo.mikeheavers.com它服務的內容exhibitcolumbus.mikeheavers.com。此外,如果您只輸入我的 droplet 的 IP 地址,它就會服務exhibitcolumbus.mikeheavers.com- 我希望它只是服務mikeheavers.com. 我混了什麼?

我通過 .conf 文件設置了兩個子域,然後sudo a2ensite [file.com.conf]

這是 selingo.mikeheavers.com.conf 的內容:

<VirtualHost *:80>
       <Directory /var/www/html>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride All
               Order allow,deny
               allow from all
       </Directory>


       ServerAdmin mheavers@gmail.com
       ServerName selingo.mikeheavers.com
       ServerAlias www.selingo.mikeheavers.com
       DocumentRoot /var/www/selingo/public_html


       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
       LogLevel warn rewrite:trace8

       RewriteEngine On
       RewriteCond %{SERVER_NAME} =selingo.mikeheavers.com
       RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

這是exhibitioncolumbus.com.conf:

<VirtualHost *:80>
       <Directory /var/www/html>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride All
               Order allow,deny
               allow from all
       </Directory>

       ServerName exhibitcolumbus.mikeheavers.com
       ServerAlias www.exhibitcolumbus.mikeheavers.com
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/exhibitcolumbus/public_html


       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
       LogLevel warn rewrite:trace8

RewriteEngine on
RewriteCond %{SERVER_NAME} =exhibitcolumbus.mikeheavers.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

我也在我的/etc/hosts文件中註意到了這一點,我不確定第一個條目來自哪裡 - 我不記得設置它:

127.0.1.1 extra extra
127.0.0.1 localhost

我還在為 SSL 使用letsencrypt,所以這可能會導致問題嗎?我看到它也創建了一些conf文件,但是它們與上面的基本相同,只是添加了:

SLCertificateFile /etc/letsencrypt/live/exhibitcolumbus.mikeheavers.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/exhibitcolumbus.mikeheavers.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/exhibitcolumbus.mikeheavers.com/chain.pem

我還為我的 droplet 上的每個子域設置了 A 記錄,這些子域指向我的 IP 地址(http://107.170.120.88/),奇怪的是它也沒有提供我的主域(應該是你在 mikeheavers.com 上看到的)

我輸入時看到這個apachectl -S

AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:443                  is a NameVirtualHost
        default server exhibitcolumbus.mikeheavers.com (/etc/apache2/sites-enabled/exhibitcolumbus.mikeheavers.com-le-ssl.conf:2)
        port 443 namevhost exhibitcolumbus.mikeheavers.com (/etc/apache2/sites-enabled/exhibitcolumbus.mikeheavers.com-le-ssl.conf:2)
                alias www.exhibitcolumbus.mikeheavers.com
        port 443 namevhost mikeheavers.com (/etc/apache2/sites-enabled/mikeheavers.com-le-ssl.conf:2)
        port 443 namevhost prototypes.mikeheavers.com (/etc/apache2/sites-enabled/prototypes.mikeheavers.com-le-ssl.conf:2)
*:80                   is a NameVirtualHost
        default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
        port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
        port 80 namevhost exhibitcolumbus.mikeheavers.com (/etc/apache2/sites-enabled/exhibitcolumbus.mikeheavers.com.conf:1)
                alias www.exhibitcolumbus.mikeheavers.com
        port 80 namevhost mosaic.mikeheavers.com (/etc/apache2/sites-enabled/mosaic.mikeheavers.com.conf:1)
        port 80 namevhost prototypes.mikeheavers.com (/etc/apache2/sites-enabled/prototypes.mikeheavers.com.conf:1)
        port 80 namevhost selingo.mikeheavers.com (/etc/apache2/sites-enabled/selingo.mikeheavers.com.conf:1)
                alias www.selingo.mikeheavers.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"

我如何解開我造成的任何混亂?

您尚未創建虛擬主機來服務https://selingo.mikeheavers.com/。因此,當訪問此 URL 時,Apache 會選擇預設虛擬主機,根據您的列表,它是default server exhibitcolumbus.mikeheavers.com.

您只需要創建一個新的虛擬主機來服務這個站點。

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