3

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

1 Answer 1

1

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

1 Comment

You can't have %1 in ProxyPassReverse nor in ProxyPass

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.