筆記-Apache 反向代理 Reverse Proxy 設定
本文于1601天之前發表,文章內容可能已經過時。
原本的 /etc/httpd/conf/httpd.conf 還有 /etc/httpd/conf.d/ssl.conf 不用動。
在 /etc/httpd/conf.d 新增檔案,看後端有多少台,一台機器一個設定檔比較好管理。
1.轉給 MAIL Server (WEBMAIL)
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://mail.abc.com/
ProxyPassReverse / http://mail.abc.com/
ServerName mail.abc.com
</VirtualHost>
2.轉給Mail Gateway Admin Console
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://192.168.70.244/Themis/
ProxyPassReverse / http://192.168.70.244/Themis/
ServerName nopam.abc.com
</VirtualHost>
這兩個都是簡單的 VirtualHost 加上 ProxyPreserveHost on 還有 ProxyPass、ProxyPassReverse 就可以了。
3.轉給Mail Server admin Console (https)
<VirtualHost *:443>
ServerName mail.abc.tw
SSLEngine on
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
SSLCertificateFile /etc/letsencrypt/live/mail.abc.tw/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mail.abc.tw/privkey.pem
ProxyPass / https://192.168.70.202/
ProxyPassReverse / https://192.168.70.202/
</VirtualHost>
稍微複雜一點點,其實也就加入SSL相關的參數還有憑證的位置。
憑證是在這台反向代理伺服器上,操作certbot 去跟letsencrypt要來的。
所以,如果要再新增一台HTTPS的反向代理也很簡單。
4.新增 owncloud Server (SSL)
同樣是在反向代理這台伺服器去跟letsencrypt要到憑證,然後參考上面的設定,改掉ServerName 還有憑證位置就可以了。
<VirtualHost *:443>
ServerName nxc.abc.tw
# DocumentRoot /var/www/site2
SSLEngine on
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
SSLCertificateFile /etc/letsencrypt/live/nxc.abc.tw/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/nxc.abc.tw/privkey.pem
#SSLCertificateChainFile /path/to/DigiCertCA.crt
ProxyPass / https://nxc.abc.tw/
ProxyPassReverse / https://nxc.abc.tw/
</VirtualHost>