I make a request to this URL: wss://domain/websockify?port=6801 The port parameter can change dynamically. How could I make ProxyPass to redirect to a dynamic port extracted from the URL?
This is the configuration that works with a predefined port:
ProxyPass /websockify ws://localhost:6801/websockify/
ProxyPassReverse /websockify ws://localhost:6801/websockify/
If I use ProxyPassMatch the apache tells me there is an error:
ProxyPassMatch ^/.*\?port=(.*)$ ws://localhost:$1/websockify/
#ProxyPass Unable to parse URL: ws://localhost:$1/websockify/
I use apache 2.4.10
This needs to be done with mod_rewrite.
Match the port from the query string. Redirect to the port that we matched in the condition with the [P] flag. Use the same match in the ProxyPassRevese.
RewriteEngine on
RewriteCond %{QUERY_STRING} port=(.*)
RewriteRule /websockify ws://localhost:%1/websockify/ [P]
ProxyPassReverse /websockify ws://localhost:%1/websockify/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With