
在我的 Apache 2.4 伺服器配置虛擬主機檔案的第二次呼叫中,我有:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName 51.89.98.21
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://51.89.98.21$1 [NC]
RewriteRule ^(.*)$ http://51.89.98.21/ [R=permanent,END,QSA]
</VirtualHost>
第三個配置虛擬主機是這個(部分):
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName www.developmentscout.com
ServerAlias developmentscout.com
UseCanonicalName Off
DocumentRoot "/var/www/vhosts/developmentscout.com/htdocs"
RewriteEngine On
RewriteCond %{REQUEST_URI} ^\.well\-known [NC,OR]
RewriteCond %{HTTP_HOST} ^developmentscout.com$ [NC]
RewriteRule ^ https://www.developmentscout.com%{REQUEST_URI} [END,QSA,R=permanent]
SSLEngine on
SSLCertificateKeyFile /etc/letsencrypt/live/developmentscout.com-0002/privkey.pem
SSLCertificateFile /etc/letsencrypt/live/developmentscout.com-0002/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/developmentscout.com-0002/chain.pem
...
連結來自https://51.89.98.21/industrie/automatisierung/ipc/11315-edge-computing 應該重定向到http://51.89.98.21但我有一個重定向到:http://51.89.98.21/industrie/automatisierung/ipc/11315-edge-computing,它向我顯示了“真實”頁面的內容。
第二個虛擬主機永遠無法到達,因為日誌中我有以下內容:
[Tue Oct 24 18:44:23.156932 2023] [ssl:debug] [pid 8958:tid 140379014039296] ssl_engine_kernel.c(383): [cliclient 98.5864998.5864998.5864998.5803199998.58033)(20032:20164:20164921963): 後續第164933): [cli]請求收到的孩子22272(伺服器www.developmentscout.com:443),參考:https://51.89.98.21/industrie/automatisierung/ipc/11315-edge-computing
顯然,https 請求轉到了錯誤的 URL,該 URL 呼叫了錯誤的 SSL 證書,然後使用了 http 連接並顯示了內容。
我嘗試使用 Letsencrypt 建立 SSL 證書,但這對 IP 來說是不可能的。因此,任何如何解決這個問題的建議都會很棒。
更新:同時,我已經為 51.89.98.21 建立了一個自簽名憑證。 (預設之後的第二個)虛擬主機是:
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName 51.89.98.21
SSLEngine on
SSLCertificateKeyFile /etc/ca-certificates/key.pem
SSLCertificateFile /etc/ca-certificates/cert.pem
RewriteEngine On
RewriteCond %{HTTP_HOST} ^51.89.98.21/$ [NC]
RewriteRule ^ https://51.89.98.21/ [END,QSA,R=permanent]
DocumentRoot /var/www/server3
</VirtualHost>
當我呼叫這個網址時:https://51.89.98.21/branche/automobil/11819-e-auto-laden-ladestecker-ladekabel 我收到 Not Found 404了。
答案1
AI告訴我,條件
RewriteCond %{HTTP_HOST} ^51.89.98.21/$ [NC]
永遠不會為真,因為 %{HTTP_HOST} 僅包含網域名稱(在本例中為 IP),不包含尾部斜線。
所以修改應該是:
RewriteCond %{REQUEST_URI} !^/$