[英]Set up an apache reverse proxy with SSL certs and multiple domains
我需要幫助將 Apache 配置為具有 https 和多個域的反向代理,這樣www.myfirstdomain.com
和www.myseconddomain.com
都指向xxxx
,而服務器將選擇性地轉發到,比如說, xxxx:2400
( myfirstdomain.com
, http), xxxx:2401
( myfirstdomain.com
, https), xxxx
:2600 ( myseconddomain.com
, http) 和xxxx:2601
( mysecondomain.com
, https)。
我嘗試了很多選擇,但最終我被卡住了,因為我每周頒發超過 5 個證書(更新),而且我無法讓它工作。
myfirstdomain.com
和www.myfirstdomain.com
(http 和 https)配置如下:
/etc/apache2/sites-available/000-default.conf
:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:2400/
ProxyPassReverse / http://127.0.0.1:2400/
</VirtualHost>
<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:2401/
ProxyPassReverse / http://127.0.0.1:2401/
</VirtualHost>
<VirtualHost *:2400>
ServerName myfirstdomain.com
ServerAlias www.myfirstdomain.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myfirstdomain/public
<Directory /var/www/html/myfirstdomain/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =myfirstdomain.com
RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteCond %{SERVER_NAME} =www.myfirstdomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:2401>
ServerName myfirstdomain.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myfirstdomain/public
<Directory /var/www/html/myfirstdomain/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =myfirstdomain.com
RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
然后我用certbot --apache
為 www 和非 www 生成了證書,我有這個文件:
/etc/apache2/sites-available/000-default-le-ssl.conf
:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:2401/
ProxyPassReverse / http://127.0.0.1:2401/
</VirtualHost>
<VirtualHost *:2401>
ServerName myfirstdomain.com
ServerAlias www.myfirstdomain.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myfirstdomain/public
<Directory /var/www/html/myfirstdomain/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =myfirstdomain.com
# RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
# RewriteCond %{SERVER_NAME} =www.myfirstdomain.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/www.myfirstdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.myfirstdomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
我也嘗試重新生成 HTTPS 證書,但它不起作用。 我該怎么做?
首先,請記住 Apache 偵聽一系列端口,例如 80 和 443。
虛擬主機使用相同的端口(80 和 443),Apache 使用您使用的域名選擇正確的文件夾。
例如, myfirstdomain.com可以顯示 /var/www/html/myfirstdomain/public,但是如果 apache 偵聽端口 80,它永遠不會匹配 *:2400 的規則。
我還沒有嘗試過,但是您可以將 ProxyPass 和 ProxyPassReverse 放在每個虛擬主機中,並將端口保留為 :80 或 :443。
當您調用myfirstdomain.com:80 時,apache 上的規則匹配並且它執行代理到另一台服務器。
看到這個答案。
LetsEncrypt 創建一個可以從 Internet 訪問的 ACME 質詢(帶有隨機字符串的文件)。 認證服務器搜索該文件,如果存在則發布證書; 如果沒有,它會拋出一個錯誤。
我不記得文件的正確路徑,但您必須驗證:
在某些 Plesk 安裝中,無法訪問 acme 文件,因為 Plesk 添加了一些自動規則。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.