設定是這樣的。我有一個網域,例如example.com
我已經使用 a 設定了 Apache2 VirtualDocumentRoot,這樣我就可以以簡單的方式將子網域指向特定資料夾:
文件sites-available/websites.conf:
ServerName example.com
ServerAlias *.example.com
VirtualDocumentRoot /var/www/websites/%1/
<Directory /var/www/websites/%1/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
因此,當您造訪時,test.example.com它會搜尋test網站目錄下的資料夾並提供服務。
這按預期工作,但我想使用 Let's Encrypt for SSL。尚無法處理通配符憑證。我該如何解決這樣的問題?
現在的情況:
安裝後讓我們使用以下命令加密證書:sudo certbot --apache -d example.com -d admin.example.com -d www.example.com
文件:sites-available/000-default.conf:
DocumentRoot /var/www/websites/current/
<Directory /var/www/websites/current/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
# Let's Encrypt Redirect
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
所有子網域仍然被重定向到https.僅限 topdomain example.com,admin.example.com並且www.example.com應該是 https 。
答案1
問題是您沒有以任何特定於網站的方式確定任何配置的範圍。
值得注意的是,「每個網站」單獨的設定檔並不是真正的 Apache httpd 功能。這只是為了管理方便而採取的(相對常見的)約定,最終Include在載入組態時使用主設定檔中的指令將所有內容合併到單一組態中。
通常這些單獨的設定檔包含其所有內容VirtualHost以限制其影響範圍,但您似乎只有全域配置,包括 http 到 https 重定向。
答案2
嘗試從伺服器建立證書
certbot certonly -d *.example.com -d admin.example.com -d www.example.com
Wildcard domains are not supported: *.example.com


