首页 公告 项目 RSS

解决kong an upstream response is buffered to a temporary file

February 17, 2020 本文有 702 个字 需要花费 2 分钟阅读

简介

今天早上去看kong的日志的时候发现有大量的警告

an upstream response is buffered to a temporary file /usr/local/kong/proxy_temp/1/00/0000000001 while reading upstream

很显然是某一个缓冲区设置太小了,所以后端请求过来的文件被临时写入了/usr/local/kong/proxy_temp/1/00/0000000001中,之后再发送到用户的浏览器

因为这种日志真的太多了,而且频繁创建文件读写硬盘对机器的性能也是会有一定影响,所以要把这个缓冲区变大

操作

百度了一下,大部分人碰到这种问题会修改下面的参数

fastcgi_buffer_size 512k;
fastcgi_buffers 6 512k;
fastcgi_busy_buffers_size 512k;

但是这个只适用于php环境,我们kong只负责把流量往后端的nginx扔,所以要修改的是下面这些参数

proxy_buffer_size
proxy_buffers
proxy_busy_buffers_size

我使用的是docker去搭建的环境,默认重启kong会根据自身的/etc/kong/kong.conf文件重写/usr/local/kong/nginx-kong.conf文件,所以我们的配置要在/etc/kong/kong.conf下修改,但是配置文件中没有和proxy_buffer_size相关的参数,我仔细看了一下,发现了下面几句

# All configuration properties respecting the naming scheme
# `nginx_<namespace>_<directive>` will result in `<directive>` being injected in
# the Nginx configuration block corresponding to the property's `<namespace>`.
# Example:
#   `nginx_proxy_large_client_header_buffers = 8 24k`
#
#   Will inject the following directive in Kong's proxy `server {}` block:
#
#   `large_client_header_buffers 8 24k;`
#
# The following namespaces are supported:
#
# - `nginx_http_<directive>`: Injects `<directive>` in Kong's `http {}` block.
# - `nginx_proxy_<directive>`: Injects `<directive>` in Kong's proxy
#   `server {}` block.
# - `nginx_http_upstream_<directive>`: Injects `<directive>` in Kong's proxy
#   `upstream {}` block.
# - `nginx_admin_<directive>`: Injects `<directive>` in Kong's Admin API
#   `server {}` block.
# - `nginx_stream_<directive>`: Injects `<directive>` in Kong's stream module
#   `stream {}` block (only effective if `stream_listen` is enabled).
# - `nginx_sproxy_<directive>`: Injects `<directive>` in Kong's stream module
#   `server {}` block (only effective if `stream_listen` is enabled).

这就很简单了,把/etc/kong/kong.conf这个文件从容器里拷贝出来,添加下面几行

nginx_http_proxy_buffer_size = 1024k
nginx_http_proxy_buffers = 4 1024k
nginx_http_proxy_busy_buffers_size = 1024k

之后挂载到容器中,在compose文件中写入

- "./kong.conf:/etc/kong/kong.conf"

之后重启

docker-compose down && docker-compose up -d

之后测试下,警告就没有了

欢迎关注我的博客www.bboy.app

Have Fun