32

i am trying to configure my apache server as proxy to serve two internal services , one listening on 8080 and should receive traffic on specific URL and the other listening on 8077 and should receive all other http traffic

I deployed and configured apache on the same server where these two services running and it is listening to 443 along with all SSL configuration and it is working fine

also I enabled the proxy_module, proxy_http_module and proxy_http2_module

What I want to achieve

if the requested URL is /webhook1 --> pass it to EP1 http://localhost:8080 and any other requested URL should be passed to EP2 http://localhost:8077

My Current Configuration towards the first service

ProxyPass /webhook1  http://localhost:8080
ProxyPassReverse /webhook1 http://localhost:8080

Now I want to define another proxy pass to be something like

ProxyPass /  http://localhost:8077
ProxyPassReverse / http://localhost:8077

putting both configuration together is not working , appreciate your help in how to configure apache to achieve my requirement

Thank you in advance

Qais Ammari
  • 1,211
  • 1
  • 11
  • 15
  • That should work, what exactly happens if you put both rules? – Dusan Bajic Aug 28 '17 at 09:01
  • when I add the second proxy all the traffic goes to the second service , so /webhook1 will be passed to 8077 instead of 8080 – Qais Ammari Aug 28 '17 at 09:30
  • I just figured out the order of proxy rules affecting how apache executes them. I was putting the root rule before the /webhook1 rule , that is why all the traffic was going out to the second service. now I put the webhook1 rule before the root rule and things started to work as expected. I am not sure if there is a better way to configure the server , but this looks a bit clumsy – Qais Ammari Aug 28 '17 at 09:35

2 Answers2

62

Put the ProxyPass rules in the correct order as required

if you want to evaluate /webhook1 rule and send it to 8080, else send the traffic to 8077 the rules should be on the following order

ProxyPass /webhook1  http://localhost:8080
ProxyPassReverse /webhook1 http://localhost:8080
ProxyPass /  http://localhost:8077
ProxyPassReverse / http://localhost:8077
Qais Ammari
  • 1,211
  • 1
  • 11
  • 15
2

You may write ssl.conf file under /etc/apache2/sites-enabled/ as follows:-

RewriteEngine on
ProxyPass /webhook1 http://127.0.0.1:8080/
ProxyPassReverse /webhook1 http://127.0.0.1:8080/
RewriteRule ^/$ /webhook1/ [R,L]

RewriteEngine on
ProxyPass / http://127.0.0.1:8087/
ProxyPassReverse / http://127.0.0.1:8087/
RewriteRule ^/$ /EP2/ [R,L]

It will automatically redirects to HTTPS if ssl certificate is configured in apache2.

  • I'm trying to redirect to tomcac (8080) and Camunda (9090). It's ok for Tomcat, not for camunda. Any sugestion is wellcome – Juan Salvador Dec 07 '21 at 20:12