【问题标题】:Reverse Proxy using Raspbian and Apache使用 Raspbian 和 Apache 的反向代理
【发布时间】: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 以使其工作?非常感谢!

【问题讨论】:

标签: apache gitlab reverse-proxy


【解决方案1】:

感谢DusanBajic,我已经找到了解决方案。

GitLab 服务器上的配置

在 GitLab 服务器上,找到该行

external_url 'http://gitlab.example.com/'

from gitlab.rb in /etc/gitlab/ 并将该行修改为

external_url 'http://gitlab.example.com/gitlab/'

然后运行以下脚本

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo reboot

然后你可以通过

访问GitLab
http://localhost/gitlab/

但您可能会发现它响应错误 502。请等待几分钟,然后重试。

代理服务器上的配置

在代理服务器上,在目录/etc/apache2/sites-available/ 中创建一个文件gitlab.conf,内容如下

# 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/gitlab/(.*) [P,L]
ProxyPass               /gitlab/               http://192.168.1.3/gitlab/
ProxyPassReverse        /gitlab/               http://192.168.1.3/gitlab/
ProxyRequests           off

然后运行以下脚本

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_html
sudo a2enmod proxy_wstunnel
sudo a2enmod rewrite

sudo a2ensite gitlab.conf
sudo systemctl reload apache2
sudo service apache2 restart

【讨论】:

    猜你喜欢
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多