我使用 Nginx 作为反向代理并缓存来自上游服务器的代理响应。
因此,在发送给我的客户端之前,我需要在这个缓存文件中添加一个 Content-Length 标头。
我尝试将$upstream_response_length变量添加到 location 指令,但它不起作用。
location /files/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_buffering on;
chunked_transfer_encoding off;
##PROXY CACHE CONFIG
proxy_cache my_cache;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers Cache-Control;
proxy_cache_valid any 30m;
add_header Content-Length $upstream_response_length;
proxy_pass http://upstream_server;
}
我怎样才能做到这一点?