如何添加一个查询参数到apache 2.4.27 ProxyPass?

wi3ka0sx  于 2022-11-16  发布在  Apache
关注(0)|答案(2)|浏览(131)

我希望将多个面向客户的URLMap到单个内部终结点,但使用查询参数来标识每个客户。
例如,客户输入https://external_host/customer1
我希望反向代理将其作为https://internal_host/app?customer=cust1转发
我已尝试以下方法:

<Location "/customer1" >
  RewriteEngine On
  RewriteRule /customer1 /customer1?customer=cust1 [QSA,P]
  ProxyPass https://<internal host>/app
  ProxyPassreverse https://<internal host>/app
</Location>

<Location "/customer2" >
  RewriteEngine On
  RewriteRule /customer2 /customer2?customer=cust2 [QSA,P]
  ProxyPass https://<internal host>/app
  ProxyPassreverse https://<internal host>/app
</Location>

基本代理工作正常,因为请求被转发到内部服务器,但不添加查询参数。
从我所做的所有阅读来看,我觉得应该有可能做我想做的事情,但不能让它发挥作用。
感谢您的指点。
祝你好运,Chris

chhqkbe1

chhqkbe11#

我解决这个问题的方法如下:

ProxyRequests off
ProxyPass /app http://<internal server>/app
ProxyPassReverse /app http://<internal server>/app

RewriteEngine on
RewriteRule ^/cust1.htm /app?client=cust1.htm [QSA,P]
RewriteRule ^/cust2.htm /app?client=cust2.htm [QSA,P]

克里斯

of1yzvn4

of1yzvn42#

问题配置中的ProxyPassProxyPassReverse被忽略,因为[QSA,P]中的P执行代理请求。
将查询参数extraparam=something添加到代理服务器的一些其他情况:

正则表达式***和***远程服务器

如果需要在规则中使用正则表达式(第一个通配符(.*)替换为$1):

RewriteEngine on
RewriteRule ^/path/to/hook/to/proxy/(.*) http://example.org/$1?extraparam=something [QSA,P]

如果代理服务器使用***https***,则应将SSLProxyEngine On添加到配置中:

RewriteEngine on
SSLProxyEngine on
RewriteRule ^/path/to/hook/to/proxy/(.*) https://example.org/$1?extraparam=something [QSA,P]

相关问题