Hello!
On Sat, Sep 6, 2014 at 4:00 AM, Rohit Joshi wrote:
> Problem was it does not resolving domain when rewrite_by_lua is used.
>
> I have to add resolver /DNS server entry.
>
> If I don't use rewrite_by_lua, proxy_pass works fine without resolver.
>
That's strange. I don't see why you need to configure "resolver" for
this. Maybe you unnecessarily use nginx variables in the server part
of the target url in "proxy_pass"?
The following standalone example emulating your use case works for me
without configuring "resolver":
upstream upstream_backend {
server localhost:8080;
# we could also enable http connection pool here by
configuring "keepalive" and etc...
}
server {
listen 8080;
location /customers {
set $new_uri '';
rewrite_by_lua '
local url = ngx.var.request_uri
local new_uri, n, err = ngx.re.sub(url,
"^/customers/", "/credit-cards/", "jo")
if new_uri then
ngx.var.new_uri = new_uri
return
end
if err then
ngx.log(ngx.ERR, "failed to do regex substitution: ", err)
end
ngx.exit(500)
';
proxy_pass http://upstream_backend$new_uri;
}
# emulated backend service:
location /credit-cards {
content_by_lua '
ngx.say("received raw uri in the backend: ",
ngx.var.request_uri)
';
}
}
Then accessing location /customers using your test request:
$ curl 'localhost:8080/customers/ps%2Fhabcdefghi%3D/credit-cards'
received raw uri in the backend:
/credit-cards/ps%2Fhabcdefghi%3D/credit-cards
$ curl 'localhost:8080/customers/ps%2Fhabcdefghi%3D/credit-cards?a=1&b=3'
received raw uri in the backend:
/credit-cards/ps%2Fhabcdefghi%3D/credit-cards?a=1&b=3
That's what you expected, right? ;)
Regards,
-agentzh