Apache Reverse Proxy to URL With Parameters

蓝咒 提交于 2019-12-25 02:53:30

问题


I am trying to setup a reverse proxy with 2 CentOS 6.5 machines running Apache 2.2.15, where the private URL contains parameters (static, same for all requests coming through the public url), so the setup should work like this:

User --> public.url/ --> private.url/?parameter=value

User --> public.url/anything --> private.url/anything?parameter=value

I have managed to setup the reverse proxy using the following directives in /etc/httpd/conf.d/reverse-proxy.conf

    ProxyRequests Off

    proxyPass / private.url:80/ connectiontimeout=5 timeout=30
    proxyPassReverse / private.url:80/

    ProxyPassReverseCookieDomain private.url public.url

    <Location />

            RequestHeader unset Accept-Encoding
            AddOutputFilterByType SUBSTITUTE text/html
            Substitute "s|private.url|public.url|i"

    </Location>

and everything works as expected:

User --> public.url/ --> private.url/

User --> public.url/anything --> private.url/anything

however I am not sure how to accomplish the addition of the ?parameter=value suffix to the private.url

Any fingers pointing in the right direction will be much appreciated!


回答1:


So I eventually got it to work the way I wanted with mod_rewrite

    #Check if string already exists
    RewriteCond %{QUERY_STRING} !(.*parameter.*) [NC]
    #Add the string and keep hidden from user with [P]
    RewriteRule ^/(.*)$ public.url/$1?parameter=value [P]

Hope someone else finds this useful



来源:https://stackoverflow.com/questions/28558357/apache-reverse-proxy-to-url-with-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!