为ProxyPass请求添加自定义标头

我有一个简单的Apache虚拟主机:

<VirtualHost *:80> ServerName hello.local ProxyPass / http://localhost:8810/ ProxyPassReverse / http://localhost:8810/ </VirtualHost> 

所有对hello.local的请求都被代理到http://localhost:8810/ 。 我想要做的是向http://localhost:8810/的http请求中添加一个头部,并使用由外部命令返回的值。 就像是

Header set MyHeader ${/usr/bin/an_external_program}

任何方式来完成这个?

好,我知道了。

首先,执行的脚本,用于获取插入到标题中的值。 我把它创build为/opt/apache/debug.sh

 #!/bin/bash #this script just loops forever and outputs a random string #every time it receives something on stdin while read do cat /dev/urandom|head -c12|base64 done 

Apacheconfiguration:

 <VirtualHost *:80> ServerName light.nik RewriteEngine On RewriteMap doheader prg:/opt/apache/debug.sh RewriteRule (.*) - [E=customheader:${doheader:},P] RequestHeader set customheader %{customheader}e ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost> 

http://localhost:8080/上运行的后端服务将使用脚本中的值接收customheader

关于使用外部程序的Apache文档在这里 。