如何保存$ sent_http_content_length的值以供nginx.conf中的IF子句使用的变量?

时间:2019-05-30 19:16:24

标签: nginx nginx-location nginx-reverse-proxy nginx-config

我想将$ sent_http_content_length的值保存在变量中,然后在IF子句中使用该值?

location / {

        root html;
        index abc.html abc.htm;



add_header X-content-length  $sent_http_content_length;

}

我的输出是

HTTP/1.1 200 OK


Server: nginx/1.12.2

Date: Thu, 30 May 2019 19:12:35 GMT

Content-Type: text/html

Content-Length: 108

Last-Modified: Fri, 24 May 2019 05:16:37 GMT

Connection: keep-alive

ETag: "5ce77e35-6c"

Accept-Ranges: bytes

X-content-length: 108       ///please focus on this part

<!DOCTYPE html>
<html>
        <body>

                <h1>My First Heading</h1>

                <p>My first paragraph.</p>

        </body>
</html>

如果我使用

location / {

        root html;
        index abc.html abc.htm;



add_header X-content-length  $sent_http_content_length;

if ($sent_http_content_length = 108)
{

        return 200 "bhai bhai";
}

}

我的输出是

HTTP/1.1 200 OK

Server: nginx/1.12.2

Date: Thu, 30 May 2019 19:12:35 GMT

Content-Type: text/html

Content-Length: 108

Last-Modified: Fri, 24 May 2019 05:16:37 GMT

Connection: keep-alive

ETag: "5ce77e35-6c"

Accept-Ranges: bytes

<!DOCTYPE html>
<html>
        <body>

                <h1>My First Heading</h1>

                <p>My first paragraph.</p>

        </body>
</html>

此输出中的两个问题:

  1. 未显示X-content-length'

  2. 我知道内容长度已经是108,那么它应该显示“ bhai bhai”。

如何解决这两个问题?

预先感谢

0 个答案:

没有答案