如何告诉client_max_body_size的客户端值

问题描述 投票:0回答:1

我想显示用户可以上传到用户的最大尺寸。

当客户端发送包含标题“GET_MAX_BODY_SIZE”的请求时,是否有任何功能,如nginx返回client_max_body_size的值?

nginx
1个回答
1
投票

可以返回允许的最大大小的标头,但是,无法动态捕获此值。在这种情况下,您必须手动输入标题中的值。

这种变化或多或少是这样的。

location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;

        # Modification here
        if ($http_x_get_max_body_size) {
                add_header "Client-Max-Body-Size" "300M";
        }
}

这样你就可以在“响应头”中使用返回值

curl -I -H "X-GET-MAX-BODY-SIZE: get" http://example.com

HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 20 Dec 2017 01:44:38 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Client-Max-Body-Size: 300M

/* ******************************************************** */

curl -I http://example.com

HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 20 Dec 2017 01:45:35 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
© www.soinside.com 2019 - 2024. All rights reserved.