Apache vhost 傳回兩個不同的站點

Apache vhost 傳回兩個不同的站點

我在伺服器上配置了兩個子網域(主網域和臨時網域),並且對於臨時網域,它會傳回兩個不同的路徑。有時它會傳回正確的 ( /var/www/html_staging) 但有時(當您刷新網頁瀏覽器幾次或當您前往子頁面時)它會返回主網站 ( /var/www/html)

Ubuntu 16.04 上的 Apache 2.4

有 3 個虛擬主機配置,兩個用於主網站,一個用於臨時網站。在連接埠 80 的虛擬主機配置中有從 http 到 https 的重定向。

000-default.conf:

<VirtualHost *:80>
    ServerName website.example.com
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    ServerAdmin [email protected]
    DocumentRoot /var/www/html


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

預設-ssl.conf:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html
        ServerName website.example.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on
        SSLCipherSuite ALL:!EXP:!NULL:!ADH:!LOW
        SSLCertificateFile /etc/apache2/ssl/*.example.com.crt
        SSLCertificateKeyFile /etc/apache2/ssl/*.example.com.key
        SSLCACertificateFile /etc/apache2/ssl/bundle.crt

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

暫存.conf:

<VirtualHost *:80>
    ServerName websitestaging.example.com
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    ServerAdmin [email protected]
    DocumentRoot /var/www/html_staging

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerName websitestaging.example.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/html_staging

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on
        SSLCipherSuite ALL:!EXP:!NULL:!ADH:!LOW
        SSLCertificateFile /etc/apache2/ssl/*.example.com.crt
        SSLCertificateKeyFile /etc/apache2/ssl/*.example.com.key
        SSLCACertificateFile /etc/apache2/ssl/bundle.crt

    </VirtualHost>
</IfModule>

輸出apache2ctl -S

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server website.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost website.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost websitestaging.example.com (/etc/apache2/sites-enabled/staging.conf:1)
*:443                  is a NameVirtualHost
         default server website.example.com (/etc/apache2/sites-enabled/default-ssl.conf:2)
         port 443 namevhost website.example.com (/etc/apache2/sites-enabled/default-ssl.conf:2)
         port 443 namevhost websitestaging.example.com (/etc/apache2/sites-enabled/staging.conf:15)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

這種行為的原因是什麼?為什麼登台有時會從正確路徑載入網站,有時會從主路徑載入?主網站已正確加載,這僅影響登台。

答案1

以防萬一您遇到與上述相同的問題。只需重新啟動整個伺服器,而不僅僅是 apache。伺服器重新啟動後一切正常。可能存在某種快取或配置尚未正確刪除,並且它正在影響整個伺服器。

相關內容