【发布时间】:2021-03-16 17:51:51
【问题描述】:
使用 Raspian 和 Apache 的反向代理
我有几台机器在它们上面运行不同的应用程序。最近我买了一个 Raspberry Pi 4,试图让它作为应用程序的反向代理服务器。假设我有三台机器 A、B 和 C,其中
答:Raspberry Pi 4,运行安装了 Apache2 的 Raspbian buster lite。 IP:192.168.1.2。我正在尝试将其配置为反向代理服务器。
B:运行 Ubuntu 18.04 的虚拟机。 IP:192.168.1.3。托管 GitLab 服务器。
C:运行 Ubuntu 18.04 的虚拟机。 IP:192.168.1.4。托管 RStudio 服务器。
我还有一个 ssl 加密的域名。假设域名是example.com。由于有一些应用程序我想被 A 路由,我想让 URL example.com/gitlab 路由到 B 和 example.com/rstudio 路由到 C。
下面的代码存储在A:/etc/apache2/sites-available/gitlab.conf,我可以将example.com路由到B,但是会影响路由到C。
# Specify path for Logs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /(.*) http://192.168.1.3/(.*) [P,L]
ProxyPass / http://192.168.1.3/
ProxyPassReverse / http://192.168.1.3/
ProxyRequests off
我也尝试将那些/ 替换为/gitlab/。但它失败了,因为当我输入example.com/gitlab 时,浏览器被重定向到example.com/users/sign_in 而不是应该的example.com/gitlab/users/sign_in。也请参考下面的脚本
# Specify path for Logs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Following lines should open gitlab directly from the url
# Map gitlab to gitlab/
RedirectMatch ^/gitlab$ /gitlab/
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /gitlab/(.*) http://192.168.1.3/(.*) [P,L]
ProxyPass /gitlab/ http://192.168.1.3/
ProxyPassReverse /gitlab/ http://192.168.1.3/
ProxyRequests off
我应该如何配置 apache 以使其工作?非常感谢!
【问题讨论】:
-
@DusanBajic。谢谢,我已经找到解决方案了。
标签: apache gitlab reverse-proxy