ngx.var.request_uri works
thanks
On Apr 17, 11:23 am, agentzh <agen...@gmail.com> wrote:
> On Tue, Apr 17, 2012 at 11:01 AM, Jianhua Qin <huaqi...@gmail.com> wrote:
> > We found that "%" in ngx.var.VARIABLE would be replace by "\x",
> > configurations as follow
> > log_format:
> > log_format test '$remote_addr - $remote_user $host
> > [$time_local] '
> > '"$request" $status $bytes_sent '
> > '"$http_referer" "$http_user_agent"
> > "$upstream_addr" '
> > '"$test_uri"';
>
> The \xDD stuff is the escaping sequence generated by the standard
> ngx_log module that generates the access log.
>
>
>
>
>
> > nginx.conf snippet:
> > location / {
> > set_by_lua $test_uri '
> > local test_uri = ngx.var.uri
>
> > return test_uri
> > ';
> > echo $test_uri;
>
> > }
> > .
>
> > curl result:
> > # curl -vhttp://127.0.0.1/test/%E6
> > * About to connect() to 127.0.0.1 port 80
> > * Trying 127.0.0.1... connected
> > * Connected to 127.0.0.1 (127.0.0.1) port 80
> >> GET /test/%E6 HTTP/1.1
> >> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> >> Host: 127.0.0.1
> >> Accept: */*
>
> > < HTTP/1.1 200 OK
> > < Server: AWS
> > < Date: Tue, 17 Apr 2012 02:50:34 GMT
> > < Content-Type: application/octet-stream
> > < Transfer-Encoding: chunked
> > < Connection: keep-alive
> > /test/?
>
> Obviously, the URI has been unescaped. And it's the expected behavior
> because $uri automatically unescapes the original URI value.
>
> If you need the original (escaped) URI string, use the $request_uri
> variable instead (or ngx.var.request_uri in Lua), but the latter will
> also include the querystring (or URI args).
>
> > * Connection #0 to host 127.0.0.1 left intact
> > * Closing connection #0
>
> > access log:
> > 127.0.0.1 - - 127.0.0.1 [17/Apr/2012:10:50:34 +0800] "GET /test/%E6
> > HTTP/1.1" 200 179 "-" "curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/
> > 7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5" "-" "/test/\xE6"
>
> The \xE6 escaping sequence is obviously generated by the ngx_log module.
>
> > How to solve?
>
> I don't see anything here is to be resolved :)
>
> Best regards,
> -agentzh- Hide quoted text -
>
> - Show quoted text -