We’re developing a web application and any Git branch can be deployed to a branch-specific directory per click in our Gitlab CI pipeline. I want to make those branches available via Apache HTTPd without static branch names in the config. How to configure a reverse proxy to a dynamic unix socket path based on the URL path?
Examples:
- http://dev-server/my_app/master/my_page → unix:/run/my_app/my_app_master.sock|http://localhost/my_page
- http://dev-server/my_app/some_branch/my_page → unix:/run/my_app/my_app_some_branch.sock|http://localhost/my_page
I could successfully configure it statically with:
<Location /my_app/master/>
ProxyPass unix:/run/my_app/my_app_master.sock|http://localhost/
</Location>
I tried something like this without success:
RewriteEngine On
RewriteRule /(.*)/(.*) http://%{HTTP_HOST}/$2 [P]
ProxyPassInterpolateEnv On
ProxyPass / unix:/run/my_app/my_app_$1.sock|http://%{HTTP_HOST}/ interpolate
In the error log I receive errors like:
Fri Jul 08 17:30:01.338046 2022] [proxy:error] [pid 1187922:tid 139644980160256] (2)No such file or directory: AH02454: HTTP: attempt to connect to Unix domain socket /run/my_app/my_app_$1.sock (%{http_host}) failed
I feel like interpolate
might not be effective at all. But I am not sure about its syntax and the syntax for referencing variables. The ProxyPassInterpolateEnv documentation doesn’t actually show an example for the interpolate
keyword.
Interestingly the log shows %{http_host}
instead of my config %{HTTP_HOST}
. I am not sure if Apache recognized the keyword or the host part is always lowercased.
I tried different syntax to reference variables but none of them very replaced:
$1
${1}
%1
%{HTTP_HOST}
(not the value I need but tested for debugging)${HTTP_HOST}
This is on Apache HTTPd 2.4.37 from Rocky Linux 8.5.