0

I've been trying to accomplish a goal of using Apache as a reverse proxy to translate HTTP to HTTPS as well as using mod_rewrite to inject a query string.

The reverse proxy works if tested without the rewrite. When adding the rewrite however, Apache appears to be looping the query string and appending it multiple times. This actually repeats and spawns a max number of worker threads until I force stop the service.

When I force stop Apache, I get following from my browser:

Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /api/uuid.

Reason: Error reading from remote server

However, the upstream server never appears to see this GET request come through.


My VirtualHost is as follows:

<VirtualHost *:80>
    RewriteEngine On
    RewriteRule ^/api/uuid /api/uuid?var=testing [P,QSA]
    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off
    ProxyPreserveHost On

    ProxyPass / https://192.168.47.108:8443
    ProxyPassReverse / https://192.168.47.108:8443

</VirtualHost>

Original GET request

http://192.168.47.118/api/uuid?domain=lab.local

Snip from access_log

192.168.47.118 - - [15/Sep/2018:01:27:36 -0500] "GET /api/uuid?var=testing&var=testing&var=testing&var=testing&var=testing&var=testing&var=testing&domain=lab.local HTTP/1.1" 502 395 "-"
  • What happens if you were to change your rule to the following: RewriteRule ^/api/uuid$ /api/uuid?var=testing [P,QSA,L]? – brendonofficial Sep 15 '18 at 14:23
  • Per Apache2 docs, [P] implies [L] – Suterusu Sep 15 '18 at 18:20
0

Even though I was using [P] which implies [L], and even explicit [L] ([QSA,P,L]), Apache was looping the request.

I made a Rewrite Condition that checked if the var was already in the query.

My working solution:

<VirtualHost *:80>
        RewriteEngine On
        RewriteCond %{QUERY_STRING} !domain
        RewriteRule ^/api/uuid /api/uuid?domain=test.local [P,QSA]
        SSLProxyEngine On
        SSLProxyVerify none
        SSLProxyCheckPeerCN off
        SSLProxyCheckPeerName off
        SSLProxyCheckPeerExpire off
        ProxyPreserveHost On

        ProxyPass / https://192.168.47.108:8443/
        ProxyPassReverse / https://192.168.47.108:8443/

</VirtualHost>
0

You need to stop the rewrite process, now it keeps appending your query string (it's recursive). I'd drop the P flag too (Force the substitution URL to be internally sent as a proxy request.)

    RewriteRule ^/api/uuid /api/uuid?var=testing [L,QSA]

Remark that, were anything following, /apid/uuid apart from query parameters, it would be lost, eg. '/api/uid/tralala', you'd lose the '/tralala'.

If you want the Proxy flag, you would need to specify the backend server, as in

RewriteRule ^/api/uuid https://192.168.47.108:8443/api/uuid?var=testing [P,QSA]

and remove the ProxyPass directive.

  • Without the [P] flag, Apache looks for the path locally at /api/uuid/ (which does not exist) and gives a 404. With the [P] flag, Apache takes anything after the '/' and forwards it on intact. – Suterusu Sep 15 '18 at 18:18
  • And what do you think the ProxlyPass is for? Ornamental? – Gerard H. Pille Sep 15 '18 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.