nginx+lua 根据指定路径反向代理

 1 location /imgproxytest{
 2 if ($uri ~ ".*.(jpg|png|jpeg|bmp|gif|swf|css)$"){
 3 rewrite_by_lua 'local url = ngx.var.request_uri local new_url = string.gsub(url,"/imgproxytest","") ngx.redirect("http://test-imaging.oss-cn-hangzhou.aliyuncs.com"..new_url) ';
 4 }
 5 }
 6 
 7 location /imgproxyprod {
 8 if ($uri ~ ".*.(jpg|png|jpeg|bmp|gif|swf|css)$"){
 9 rewrite_by_lua 'local url = ngx.var.request_uri local new_url = string.gsub(url,"/imgproxyprod","") ngx.redirect("http://imaging.oss-cn-hangzhou.aliyuncs.com"..new_url) ';
10 }
11 
12 }
原文地址:https://www.cnblogs.com/chenru1988/p/8652678.html