36

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

3
  • That should work, what exactly happens if you put both rules? Commented Aug 28, 2017 at 9: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 Commented Aug 28, 2017 at 9: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 Commented Aug 28, 2017 at 9:35

2 Answers 2

72

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
Sign up to request clarification or add additional context in comments.

5 Comments

Fantastic answer!! I had a similar scenario and this worked flawlessly
@KalyanPradhan glad that helped !
Which file in Apache contains this configuration? I use Apache 2.2
normally this should be in <Apache-Home>/conf/httpd.conf , i.e. /etc/httpd/conf/httpd.conf
The /etc/httpd directory is used in RHEL based distros (e.g. CentOS, Alma, Rocky etc.) whereas Debian based distros (e.g. Ubuntu) use /etc/apache2 as the conf directory for Apache.
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.

1 Comment

I'm trying to redirect to tomcac (8080) and Camunda (9090). It's ok for Tomcat, not for camunda. Any sugestion is wellcome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.