我在过去几个月里一直试图将Apache用作反向代理,但我无法按照我想要的方式配置它 .

Network configuration

在我的本地网络中,所有传入的HTTP请求都由我的防火墙路由到Apache服务器(在 Debian 上运行) . 此Apache服务器托管3种不同的Web服务 .

第四个Web服务 Gitlab 托管在第二台服务器( Ubuntu )上,并在docker中运行 . Gitlab被我的内部DNS引用为 gitlab/ . 所以,我可以在我的浏览器中从URL http://gitlab/ 访问它 .

Desired Apache behavior

我想通过在我的浏览器中输入以下来从Internet访问这4种不同的Web服务:

http://ip_address/web_service_1/
http://ip_address/web_service_2/
http://ip_address/web_service_3/
http://ip_address/gitlab/

Web_service_1到web_service_3完美运行 . 但我无法想象如何将Apache配置为Gitlab的代理 .

从互联网上,对Gitlab的请求应该通过防火墙,路由到运行Apache的 Debian 服务器,最后到运行Gitlab的 Ubuntu 服务器 .

不幸的是,当我向 http://ip_address/gitlab 发送请求时,我收到了 http://ip_address/users/sign_in 而不是 http://ip_address/gitlab/users/sign_in ,并且Apache无法将下一个请求路由到Gitlab,因为 /gitlab/ 部分消失了 .

Apache configuration

为了得到上面解释的结果,我在Debian服务器上创建了一个名为 /etc/apache2/sites-available/proxy.conf 的文件,其中包含:

<VirtualHost *:80>
   ServerName myProxy
   RewriteEngine On
   RewriteRule ^/web_service_1(.*) http://debian_server/web_service_1/$1
   RewriteRule ^/web_service_2(.*) http://debian_server/web_service_2/$1
   RewriteRule ^/web_service_3(.*) http://debian_server/web_service_3/$1
   ProxyPass /gitlab http://gitlab/
   ProxyPassReverse /gitlab http://gitlab/
</VirtualHost>

如您所知,这不能按预期工作: /gitlab/ 部分从URL中消失 .

经过大量的研究和测试,我找到了一个教程,它给我带来了更好的结果......也没有工作 . 我的 proxy.conf 现在是:

<VirtualHost *:80>  
    ServerName myProxy 
    ServerAlias myProxy
    DocumentRoot /var/www/html
    RewriteEngine On
    LogLevel error trace6
    RewriteRule ^/web_service_1(.*) http://127.0.2.1/web_service_1/$1 [P]
    RewriteRule ^/web_service_2(.*) http://127.0.2.2/web_service_2/$1 [P]   
    RewriteRule ^/web_service_3(.*) http://127.0.2.3/web_service_3/$1 [P]   
    ProxyRequests Off

    ProxyPass /gitlab/ http://gitlab/

    ProxyHTMLURLMap http://gitlab /gitlab

    <Location /gitlab/>
        ProxyPassReverse /
        ProxyHTMLEnable On
        ProxyHTMLURLMap / /gitlab/
        RequestHeader unset Accept-Encoding
    </Location>
</VirtualHost>

有了这个解决方案,我几乎得到了登录页面,但是有些元素丢失了,我无法登录 . 也许我在代理配置中忘记了一些选项...

有谁知道如何改进这个解决方案并使其有效?

非常感谢你的帮助 .