
/etc/apache2/sites-available/my_domain.conf
我想將某個子路徑重定向到在連接埠 19011 運行的後端應用程式。
<VirtualHost *:80>
ServerName my_domain
DocumentRoot /var/www/my_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /my_subpath/ http://localhost:19011/
ProxyPassReverse /my_subpath/ http://localhost:19011/
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/letsencrypt/live/my_domain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my_domain/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName my_domain
DocumentRoot /var/www/my_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /my_subpath/ http://localhost:19011/
ProxyPassReverse /my_subpath/ http://localhost:19011/
</VirtualHost>
此配置適用於 HTTP,但不適用於 HTTPS:
http://my_domain/my_subpath
按預期轉到後端應用程序,而https://my_domain/my_subpath
返回 404
我是一個 apache 菜鳥,所以我不知道為什麼這不起作用。我在 apache 日誌中也沒有看到任何錯誤。我在conf文件中缺少什麼?
版本:
- 阿帕契:2.4.29
- 作業系統:Ubuntu 18.04.5
答案1
事實證明我的conf檔案沒有任何問題。my_domain-le-ssl.conf
下還有另一個名為 的conf 文件/etc/apache2/sites-available
,它是在我使用 Letsencrypt 建立 SSL 憑證後自動建立的。該conf 檔案還包含連接埠 443 的虛擬主機,Apache 使用該虛擬主機來服務 SSL 請求。
如有疑問,請執行sudo apachectl -S
以查看您的活動虛擬主機配置。就我而言,它返回了這樣的內容:
*:80 my_domain (/etc/apache2/sites-enabled/my_domain.conf:1)
*:443 my_domain (/etc/apache2/sites-enabled/my_domain-le-ssl.conf:2)
*:443 my_domain (/etc/apache2/sites-enabled/my_domain.conf:10)