
我們在 Ubuntu 伺服器上使用 Apache 來託管我們的網站。 SSL 憑證由 LetsEncrypt 提供,過去幾年一切正常。
上週五我嘗試更新其中一張證書,但沒有成功。 .well-known/acme-challenge 資料夾未創建,我在過去幾天嘗試了幾件事,現在更糟:我們有一個主域domain1.de 和第二個網域domain2.com。 domain1.de 與 SSL 配合良好。現在,domain2.com 始終顯示domain1.de 網站。
設定檔適用於domain1.de:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName domain1.de
ServerAlias www.domain1.de
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
和 SSL:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
ServerName domain1.de
ServerAlias www2.domain1.de
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/www2.domain1.de/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www2.domain1.de/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/www2.domain1.de/fullchain.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
設定檔適用於domain2.com:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/domain2.com
ErrorLog ${APACHE_LOG_DIR}/error_journalsuite_com.log
CustomLog ${APACHE_LOG_DIR}/access_journalsuite_com.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain2.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
apachectl -S 輸出:
root@domain1new /var/www/domain2.com # apachectl -S
VirtualHost configuration:
*:443 domain1.de (/etc/apache2/sites-enabled/domain1.de-ssl.conf:2)
*:80 is a NameVirtualHost
default server domain1.de (/etc/apache2/sites-enabled/domain1.de.conf:1)
port 80 namevhost domain1.de (/etc/apache2/sites-enabled/domain1.de.conf:1)
alias www2.domain1.de
port 80 namevhost domain2.com (/etc/apache2/sites-enabled/domain2.com.conf:1)
alias www.domain2.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
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
您缺少domain2.com 的HTTPS 連接埠443 的配置。連接埠 80 的 HTTP 可以正常運作。如果您對其進行測試,curl -v http://domain2.com
您會發現它正在工作,但重定向到https://domain2.com
(根據您的RewriteRule
),它沒有正確的配置並使用預設的VirtualHost _default_:443
網域domain1.de
。如果您檢查,curl -v -k https://domain2.com
您會發現它提供了 TLS 證書,domain1.de
而且確實301 Redirect
如此https://www2.domain1.de/
。
要解決您的問題,您需要建立<VirtualHost *:443>
適當ServerName domain2.com
的 SSLEngine 配置設定。