In the build environment of my company, we are not allowed to access https://github.com directly, but only via a mirror https://mycompany.corp/github-proxy/mirror/. I would like to rewrite requests to github such that the mirror is used. I was tying to setup apache2 with mod_rewrite and mod_proxy as described here https://stackoverflow.com/a/35371232/9759769, but didn't manage to setup the rewrite rules correctly.
When I use curl to request github, the proxy is working but the url is not rewritten.
Here is my current docker configuration:
Dockerfile:
FROM ubuntu:22.04
RUN set -ex; \
\
apt-get clean; \
apt-get update; \
apt-get install -y --no-install-recommends \
wget \
curl \
git \
vim \
ca-certificates \
apache2; \
rm -r /var/lib/apt/lists/*;
ADD forward_proxy.conf /etc/apache2/sites-available/
ADD proxy.conf /etc/apache2/mods-available/
RUN set -ex; \
a2enmod proxy proxy_http proxy_connect rewrite ssl; \
a2ensite forward_proxy.conf; \
a2dissite 000-default.conf;
RUN apache2ctl configtest
ENV HTTP_PROXY="http://localhost:80"
ENV HTTPS_PROXY="http://localhost:80"
forward_proxy.conf:
<VirtualHost *:80>
RewriteEngine on
RewriteRule https://github.com/(.*) https://mycompany.corp/github-proxy/mirror/$1" [R,L]
SSLProxyEngine on
ProxyRequests on
AllowCONNECT 80 443
ProxyPreserveHost off
ErrorLog /var/log/apache2/forward_proxy.error.log
CustomLog /var/log/apache2/forward_proxy.access.log common
</VirtualHost>
proxy.conf:
<IfModule mod_proxy.c>
# If you want to use apache2 as a forward proxy, uncomment the
# 'ProxyRequests On' line and the <Proxy *> block below.
# WARNING: Be careful to restrict access inside the <Proxy *> block.
# Open proxy servers are dangerous both to your network and to the
# Internet at large.
#
# If you only want to use apache2 as a reverse proxy/gateway in
# front of some web application server, you DON'T need
# 'ProxyRequests On'.
ProxyRequests On
<Proxy *>
AddDefaultCharset off
Require local
</Proxy>
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
#ProxyVia Off
</IfModule>