简体   繁体   English

Apache反向代理到URL带参数

[英]Apache Reverse Proxy to URL With Parameters

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:我正在尝试使用运行 Apache 2.2.15 的 2 台 CentOS 6.5 机器设置反向代理,其中私有URL 包含参数(静态,对于通过公共 url 发出的所有请求相同),因此设置应该像这样工作:

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

User --> public.url/anything --> private.url/anything?parameter=value用户 --> 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我已经设法使用 /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/用户 --> public.url/ --> private.url/

User --> public.url/anything --> private.url/anything用户 --> 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但是我不确定如何完成将?parameter=value后缀添加到 private.url

Any fingers pointing in the right direction will be much appreciated!任何指向正确方向的手指将不胜感激!

So I eventually got it to work the way I wanted with mod_rewrite 所以我最终使它按照我想要的方式与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 希望其他人觉得这有用

reminder: it does not work in location context according to documentation https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule提醒:根据文档https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule ,它在位置上下文中不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM