[英]NGINX $request_uri vs $uri
How do you determine when to use $request_uri
vs $uri
? 你如何确定何时使用$request_uri
vs $uri
?
According to NGINX documentation, $request_uri
is the original request (for example, /foo/bar.php?arg=baz
includes arguments and can't be modified) but $uri
refers to the altered URI. 根据NGINX文档, $request_uri
是原始请求(例如,/ /foo/bar.php?arg=baz
包含参数,不能修改)但$uri
指的是更改的URI。
If the URI doesn't change, does $uri = $request_uri? 如果URI没有改变,$ uri = $ request_uri?
Would it be incorrect or better or worse to use: 使用时是不正确的,更好的还是更糟的:
map $uri $new_uri {
# do something
}
vs VS
map $request_uri $new_uri {
# do something
}
$uri
is not equivalent to $request_uri
. $uri
不等于$request_uri
。
The $uri
variable is set to the URI that nginx
is currently processing - but it is also subject to normalisation, including: $uri
变量设置为nginx
当前正在处理的URI - 但它也需要进行规范化,包括:
?
去掉?
and query string 和查询字符串 /
characters are replace by a single /
连续/
字符替换为单个/
The value of $request_uri
is always the original URI and is not subject to any of the above normalisations. $request_uri
的值始终是原始URI,不受上述任何规范化的约束。
Most of the time you would use $uri
, because it is normalised. 大多数时候你会使用$uri
,因为它是标准化的。 Using $request_uri
in the wrong place can cause URL encoded characters to become doubly encoded. 在错误的位置使用$request_uri
会导致URL编码的字符变为双重编码。
Use $request_uri
in a map
directive, if you need to match the URI and its query string. 如果需要匹配URI及其查询字符串,请在map
指令中使用$request_uri
。
Another difference about $uri
and $request_uri
in proxy_cache_key
is $request_uri
will include anchor tags part
, but $uri$is_args$args
will ignore it 关于另一个区别$uri
和$request_uri
在proxy_cache_key
是$request_uri
将包括anchor tags part
,但$uri$is_args$args
会忽略它
Do a curl operation : curl -I static.io/hello.htm?id=1#/favor/goods
: 做一个卷曲操作: curl -I static.io/hello.htm?id=1#/favor/goods
:
proxy_cache_key $scheme://$host$uri$is_args$args; => Cache KEY: http://static.io/hello.htm?id=1
proxy_cache_key $scheme://$host$request_uri; => Cache KEY: http://static.io/hello.htm?id=1#/favor/goods
Nginx Document: http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_uri Nginx文件: http : //nginx.org/en/docs/http/ngx_http_core_module.html#var_request_uri
$request_uri
: full original request URI (with arguments) $request_uri
:完整的原始请求URI(带参数) $uri
: current URI in request, normalized The value of $uri may change during request processing, eg when doing internal redirects, or when using index files. $uri
:请求中的当前URI,规范化$ uri的值可能在请求处理期间发生变化,例如在执行内部重定向或使用索引文件时。 Proxy Cache key: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_key 代理缓存密钥: http : //nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_key
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.