nginx的location模块的官方文档的一些部分翻译不通求解

官方文档地址

可以用Ctrl+F页内搜索找到原文的位置和上下文

If a location is defined by a prefix string that ends with the slash character, and requests are processed by one of proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, memcached_pass, or grpc_pass, then the special processing is performed. In response to a request with URI equal to this string, but without the trailing slash, a permanent redirect with the code 301 will be returned to the requested URI with the slash appended. If this is not desired, an exact match of the URI and location could be defined like this:

中的

In response to a request with URI equal to this string, but without the trailing slash, a permanent redirect with the code 301 will be returned to the requested URI with the slash appended.

这一段到底说了什么?能否举一个例子说明一下?


after decoding the text encoded in the “%XX” form

所谓 “%XX” form 是一种什么形式?


and possible compression of two or more adjacent slashes into a single slash.

为什么会出现几个'/'相邻的情况?(如果这种情况是错误的话,nginx应该不会说会对它进行处理)


The “@” prefix defines a named location. Such a location is not used for a regular request processing, but instead used for request redirection. They cannot be nested, and cannot contain nested locations.

什么叫做不会被用来做正常的请求处理,但会用来请求重定向?也就是说这个location块中不能使用root之类的东西,必须使用proxy_pass之类的?

另外这个@前缀,前在什么地方?location @ ...吗?


谢谢

阅读 2.4k
1 个回答
location /path/ {
    proxy_pass: ......;
}

如果请求时 /path (没有最后的 /),会返回一个 301 重定向到 /path/


%XX 是 percentage encoding


为什么会出现几个'/'相邻的情况?

URL 是人输入的,出现啥都不奇怪。

path 是由服务器解释的,服务器说啥合法啥就合法


@ 开始的 location 是没有办法从外部访问的,但是可以用于内部重定向。(proxy_pass 不是用于内部重定向的)

就在你给的文档里搜索 @ ,就能看到几个例子。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题