首页 > 解决方案 > nginx.conf 中的“location /logs”和“location /logs/”有什么区别

问题描述

我需要知道nginx.conf中以下两行之间的区别。以及它们的用例。

位置/日志{

位置/日志/ {

标签: javasecuritynginxwebservernginx-config

解决方案


这在http://nginx.org/en/docs/http/ngx_http_core_module.html#location的位置文档中有介绍

如果位置由以斜杠字符结尾的前缀字符串定义,并且请求由 proxy_pass、fastcgi_pass、uwsgi_pass、scgi_pass、memcached_pa​​ss 或 grpc_pass 之一处理,则执行特殊处理。为了响应 URI 等于此字符串但没有尾部斜杠的请求,将返回带有代码 301 的永久重定向到附加斜杠的请求 URI。如果不希望这样,可以像这样定义 URI 和位置的精确匹配:

location /user/ {
    proxy_pass http://user.example.com;
}

location = /user {
    proxy_pass http://login.example.com;
}

我希望这会有所帮助。


推荐阅读