URI中的正则表达式用于代理传递 [英] regex in URI for proxy passing
问题描述
我的nginx中有以下配置:
I have following config in my nginx:
location / {
if ($request_uri ~* ^/checkout/(dev-dist|dist|images|js|libs|resources|angular4-hybrid|bundle.js)) {
proxy_pass http://static-qa-uscentral1.company.com/hybrid/live$request_uri;
break;
}
}
我正在尝试在istio的虚拟服务中复制它
I am trying to replicate this in istio's virtual service
我已经编写了以下虚拟服务来匹配此正则表达式:
I have written following virtual service to match this regex:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: routes-static
namespace: mui-relqa
spec:
gateways:
- my-gateway
hosts:
- "*"
http:
- match:
- uri:
regex: '^./checkout/(dev-dist|dist|images|js|libs|resources|angular4-hybrid|bundle.js).*$'
redirect:
authority: static-qa-uscentral1.company.com
uri: /hybrid/live
我不愿透露以下几点:
-
如何使用nginx配置中使用的$ request_uri在虚拟服务中复制
how to use that $request_uri used in nginx config to replicate in virtual service
使用上述虚拟服务,它将完全将调用重定向到"static-qa-uscentral1.company.com",我在"virtualservice" yaml的"authority"参数中提到了该调用.我如何实现nginx在proxy_pass期间所做的工作,该操作不会更改URL,但仍会获取重定向URL的内容.
using the above virtual service it will totally redirect the calls to "static-qa-uscentral1.company.com" which I have mentioned in "authority" parameter in "virtualservice" yaml. How can I achieve what nginx does during proxy_pass which doesnot change the URL but still gets the content of redirected URL.
推荐答案
You could probably use Istio Envoy filter, you might want to check other rewrite options for Envoy HTTP routing.
您可以查看从NGINX迁移到特使代理.在第4步中,它们显示了proxy_pass
的示例.
You can have a look at Katacoda Migrating from NGINX to Envoy Proxy. In step 4 they show example of proxy_pass
.
正则表达式将匹配基于正则表达式的ECMAscript样式,您甚至可以查看 Istio虚拟服务源代码.
Regex will match ECMAscript style regex-based, you can even have a look into Istio Virtual Service source code.
您需要删除Istio
并设置 NGINX Ingress Controller
,或者在Istio
后面设置Ingress Controller
,以便它将基于nginx.conf或使用
You would need to either remove Istio
and setup NGINX Ingress Controller
instead, or setup the Ingress Controller
behind Istio
so it would redirect and/or proxy the traffic based on nginx.conf or using Nginx Annotations
.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/server-snippet: |
set $agentflag 0;
if ($http_user_agent ~* "(Mobile)" ){
set $agentflag 1;
}
if ( $agentflag = 1 ) {
return 301 https://m.example.com;
}
更新
OP提到了这一点,Envoy还支持 Lua脚本实际上允许在代理中注入任意代码以处理请求.
This was mentioned by the OP, Envoy also supports Lua scripting that allows essentially injecting arbitrary code in the proxy to process requests.
这篇关于URI中的正则表达式用于代理传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!