Score:0

Apache proxy to back end services

az flag

I need to create a conf file for apache web server (Linux) , that will act as proxy for multiple back end services om the same server. Each backend service is running as systemd service on separate ports.

The conf file contains following

<VirtualHost: *:80>
    ProxyPass /api/policies/???  http://127.0.0.1:6001/
    ProxyPassReverse /api/policies/???  http://127.0.0.1:6001/

    ProxyPass /api/policies/???/coverages http://127.0.0.1:6002/
    ProxyPassReverse /api/policies/???/coverages http://127.0.0.1:6002/

    ProxyPass /api/policies/???/premiums http://127.0.0.1:6003/
    ProxyPassReverse /api/policies/???/coverages http://127.0.0.1:6003/

</VirtualHost>

??? – refers to request parameter which will be part of the url How do I define this in the conf ? what kind of expression needs to be used

Score:2
us flag
Rob

Several approaches are possible.

  1. Enclose the ProxyPass directives in correctly ordered LocationMatch directives ; something along the lines of

    <LocationMatch "/api/policies/(.*)/coverages">
        ProxyPass  http://127.0.0.1:6002/
        # ...
    </LocationMatch>
    <LocationMatch "/api/policies/(.*)/premiums">
        ProxyPass  http://127.0.0.1:6003/
        # ...
    </LocationMatch>
    <Location "/api/policies/">
        ProxyPass  http://127.0.0.1:6001/
        # ...
    </Location>
    
  2. Use the mod_rewrite reverse proxy target [P]rather than ProxyPass directives to allow pattern matching.

     RewriteRule    "^/api/policies/(.*)/coverages/(.*)"  "http://127.0.0.1:6002/"  [P]
     RewriteRule    "^/api/policies/(.*)/premiums/(.*)"  "http://127.0.0.1:6003/"  [P]
    
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.