例如,如果您最初使用以下配置设置了反向代理:ProxyPass/http://192.168.1.100/ProxyPassReverse/http://192.168.1.100/可以通过在 RewriteRule 上使用 代理标志使其成为有条件的.示例配置可能如下所示:RewriteEngine OnProxyPassInterpolateEnv 开启RewriteCond "%{REMOTE_ADDR}" =50.12.95.78RewriteRule (.*) http://192.168.1.100/quote$1 [P,E=proxy_pass_path:/quote]RewriteRule (.*) http://192.168.1.100$1 [P]ProxyPassReverse/http://192.168.1.100${proxy_pass_path}/插值第一个 RewriteRule 仅在前面的RewriteCond 指令匹配,即如果远程 IP地址是 50.12.95.78.[P]roxy 标志还可以防止应用进一步的 RewriteRule 指令.环境变量 proxy_pass_path 设置为告诉 ProxyPathReverse 指令路径已被修改.第二个RewriteRule如果第一个未评估,则会自动应用.最后,ProxyPathReverse 指令被修改以重写响应头基于 proxy_pass_path 变量.超出您的问题范围,请记住,这种代理不会实现任何实际形式的安全性.50.12.95.78 以外的 IP 地址仍然可以通过请求 http:///quote 来访问 http://192.168.1.100/quote.if request comes from public ip 50.12.95.78. Proxypass to http://192.168.1.100/quote url.if request comes from other public ip . Proxypass to http://192.168.1.100/ urlWhat is the settings for it in apache? Reverse proxy wont work in if condition. 解决方案 You can set up a conditional reverse proxy in Apache httpd by utilizing mod_proxy and mod_rewrite.For instance, if you originally had your reverse proxy set up with the following configuration:ProxyPass / http://192.168.1.100/ProxyPassReverse / http://192.168.1.100/It can be made conditional by using the proxy flag on a RewriteRule. An example configuration could look like this:RewriteEngine OnProxyPassInterpolateEnv OnRewriteCond "%{REMOTE_ADDR}" =50.12.95.78RewriteRule (.*) http://192.168.1.100/quote$1 [P,E=proxy_pass_path:/quote]RewriteRule (.*) http://192.168.1.100$1 [P]ProxyPassReverse / http://192.168.1.100${proxy_pass_path}/ interpolateThe first RewriteRule is applied and proxied only if the precedingRewriteCond directive is matched, i.e. if the Remote IPAddress is 50.12.95.78.The [P]roxy flag also prevents further RewriteRule directives from being applied.The environmental variable proxy_pass_path is set to tell the ProxyPathReverse directive that the path has been modified.The second RewriteRuleis automatically applied if the first did not evaluate.Finally, theProxyPathReverse directive is modified to rewrite response headersbased on the proxy_pass_path variable.Going beyond the scope of your question, bear in mind that this kind of proxy will not implement any real form of security. IP addresses other than 50.12.95.78 will still be able to access http://192.168.1.100/quote simply by requesting http://<Proxy_Host>/quote. 这篇关于apache 中的条件反向代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-17 15:47
查看更多