1

I am trying to configure my Apache httpd VirtualHost to dynamically proxy to a nodejs app based on the user and app in the URL.

An internal user visits the web server at…

https://mywebserver/<user>/<appname> 

Apache httpd should extract user and appname, and pass them to a bash script which returns “port” (or 0 if there's some error). [This script will also start the nodejs app if it’s not already running]. Apache httpd should then proxy the request from:

https://mywebserver/<user>/<appname> 

to:

http://localhost:<port> 

I was experimenting with the results provided by ChatGPT, but each time I try this there is another syntax error that is not valid Apache httpd syntax.

In general, I suspect that the port lookup should happen in a RewriteMap call. I'm pretty sure I can extract the user and app through Rewrite, but not sure how to connect that to a ProxyPass/ProxyPassReverse call.

Now, I could just hard-code all the user/app/port combinations in the configuration, and that would probably "simplify" things, but a dynamic configuration is ideal because new apps can be added or removed by developers at any time. and can be added or removed at any time.

Any help would be greatly appreciated.

Note: To simplify things, I really only need the parts of the configuration related to the above, and not the whole configuration.

1 Answer 1

0

I believe the answer to my question is the following:

RewriteEngine On RewriteMap portmap "prg:/path/to/port_lookup_script.sh" # Capture user and app RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+) # Proxy to internal localhost RewriteRule ^/(.*)/(.*)$ http://localhost:${portmap:%1,%2}%{REQUEST_URI}?%{QUERY_STRING} [P] ProxyPassReverse / http://localhost/ 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.