
許多線上 ubuntu 伺服器教學只向您展示如何設定反向代理,但沒有解釋如何使用 SSL 進行設置,讓其與伺服器上的其他網域一起加密和設定。是否有關於如何設定以下內容的簡潔教學:
- apache反向代理存取內部應用程式
- 設定 ssl 允許加密該應用程式以透過 https 存取它
答案1
假設您的 ubuntu 伺服器上安裝了 apache,您需要使用 root 安裝代理模組:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
安裝後,您需要修改 /etc/apache2/sites-available/000-default.conf 檔案以新增網站。使用下面的例子:
<VirtualHost *:80>
ServerName xxxx.yyyy.com
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:26876/
ProxyPassReverse / http://127.0.0.1:26876/
<Directory /var/www>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =testardor.xcubicle.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
設定完成後,您需要使用以下命令重新啟動 apache:systemctl 重新啟動 apache2
現在使用 Lets Encrypt 進行 SSL 設定。起初,設定 SSL 似乎很混亂,但其實很簡單。按照本教學操作:https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-18-04
其簡單如下:
sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-apache
sudo certbot --apache
按照提示和您的設定進行操作。記得重啟你的apache。
注意:如果您已經進行了 Lets Encrypt 設定並新增了新網域,則只需刪除 000-default-le-ssl.conf 文件,然後讓 certbot 重新產生它即可。我遇到了問題並且需要這樣做。