NGINX $ request

编程入门 行业动态 更新时间:2024-10-10 04:20:16
本文介绍了NGINX $ request_uri和$ uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您如何确定何时使用$request_uri和$uri?

How do you determine when to use $request_uri vs $uri?

根据NGINX文档,$request_uri是原始请求(例如,/foo/bar.php?arg=baz包含参数且不能修改),但是$uri指的是更改后的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.

如果URI不变,那么$ uri = $ request_uri吗?

If the URI doesn't change, does $uri = $request_uri?

使用不正确,更好或更差的东西吗?

Would it be incorrect or better or worse to use:

map $uri $new_uri { # do something }

vs

map $request_uri $new_uri { # do something }

推荐答案

$uri不等同于$request_uri.

$uri变量被设置为nginx当前正在处理的URI -但也要进行标准化,包括:

The $uri variable is set to the URI that nginx is currently processing - but it is also subject to normalisation, including:

  • 删除?和查询字符串
  • 连续的/字符被单个/
  • 替换
  • URL编码字符被解码
  • Removal of the ? and query string
  • Consecutive / characters are replace by a single /
  • URL encoded characters are decoded

$request_uri的值始终是原始URI,并且不受上述任何规范化的约束.

The value of $request_uri is always the original URI and is not subject to any of the above normalisations.

大多数情况下,您会使用$uri,因为它已标准化.在错误的位置使用$request_uri可能导致URL编码的字符变得双重编码.

Most of the time you would use $uri, because it is normalised. Using $request_uri in the wrong place can cause URL encoded characters to become doubly encoded.

如果需要匹配URI及其查询字符串,请在map指令中使用$request_uri.

Use $request_uri in a map directive, if you need to match the URI and its query string.

更多推荐

NGINX $ request

本文发布于:2023-10-10 18:38:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NGINX   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!