added more complex samples to the docs for ngx.req.set_uri().

This commit is contained in:
agentzh (章亦春) 2011-10-16 11:08:56 +08:00
Родитель 89dcc5b8d3
Коммит 6be7dad626
3 изменённых файлов: 59 добавлений и 0 удалений

17
README
Просмотреть файл

@ -1130,6 +1130,23 @@ Nginx API for Lua
ngx.req.set_uri("/foo", true)
A more sophisticated example involving regex substitutions is as follows
location /test {
rewrite_by_lua '
local uri = ngx.re.sub(ngx.var.uri, "^/test/(.*)", "$1", "o")
ngx.req.set_uri(uri, true)
';
proxy_pass http://my_backend;
}
which is functionally equivalent to
location /test {
rewrite ^/test/(.*) /$1 break;
proxy_pass http://my_backend;
}
Note that you cannot use this interface to rewrite URI arguments, and
you need to use ngx.req.set_uri_args for that. For instance, Nginx
config

Просмотреть файл

@ -1227,6 +1227,27 @@ can be coded in Lua as
ngx.req.set_uri("/foo", true)
A more sophisticated example involving regex substitutions is as follows
location /test {
rewrite_by_lua '
local uri = ngx.re.sub(ngx.var.uri, "^/test/(.*)", "$1", "o")
ngx.req.set_uri(uri, true)
';
proxy_pass http://my_backend;
}
which is functionally equivalent to
location /test {
rewrite ^/test/(.*) /$1 break;
proxy_pass http://my_backend;
}
Note that you cannot use this interface to rewrite URI arguments, and you need to use [ngx.req.set_uri_args](http://wiki.nginx.org/HttpLuaModule#ngx.req.set_uri_args) for that. For instance, Nginx config

Просмотреть файл

@ -1192,6 +1192,27 @@ can be coded in Lua as
ngx.req.set_uri("/foo", true)
</geshi>
A more sophisticated example involving regex substitutions is as follows
<geshi lang="nginx">
location /test {
rewrite_by_lua '
local uri = ngx.re.sub(ngx.var.uri, "^/test/(.*)", "$1", "o")
ngx.req.set_uri(uri, true)
';
proxy_pass http://my_backend;
}
</geshi>
which is functionally equivalent to
<geshi lang="nginx">
location /test {
rewrite ^/test/(.*) /$1 break;
proxy_pass http://my_backend;
}
</geshi>
Note that you cannot use this interface to rewrite URI arguments, and you need to use [[#ngx.req.set_uri_args|ngx.req.set_uri_args]] for that. For instance, Nginx config
<geshi lang="nginx">