【问题标题】:nginx - where can I put client_max_body_size property?nginx - 我可以在哪里放置 client_max_body_size 属性?
【发布时间】:2017-03-12 16:02:26
【问题描述】:

我需要在某些 url 甚至全局应用程序上使用 - client_max_body_size 属性(通过 nginx.conf)限制最大正文大小。

我发现这个属性记录在 nginx 网站上:

Syntax:   client_max_body_size size;
Default:  
client_max_body_size 1m;
Context:  http, server, location
Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in

一个请求超过了配置的值,413(Request Entity Too 大)错误返回给客户端。请注意浏览器 无法正确显示此错误。将大小设置为 0 禁用 检查客户端请求正文大小。

我需要将此属性设置为我的应用程序的某个部分(不是全局),所以我想将其设置为指定的 url,例如http://localhost:8088/x/#/y(# 是强制性的)

这个特定网址的语法是什么?有可能吗?

【问题讨论】:

标签: java nginx


【解决方案1】:

您可以设置 client_max_body_size 创建位置块:

location = /x {
   client_max_body_size 10M;
}

不幸的是,由于片段永远不会通过 http 发送,因此无法创建 location 块来挂钩片段。

我不知道/x/#/y背后的逻辑,但你可以开始在/x中设置client_max_body_size

【讨论】:

  • 那是我之前已经尝试过的,所以正如你所说,我无法为这个问题制定 url 规范?
  • 片段不随请求一起发送,因此以这种方式似乎不可行。
  • 我的建议是为该特定请求使用专用端点,更直接