2

Trying to configure Nginx from Kong because the nginx default config has a proxy temp file limit that blocks 1GB downloads (or larger). A complication is that Kong runs in a docker container so we start cold every time.

We are using Kong as a reverse proxy, it provides https service and redirects requests in the clear to a slew of micro services, that works fine. My question is similar to this: NgInx as reverse proxy with Kong

Anyhow this page taught us to add an Nginx config parameter that disables use of a temp file: https://www.scalescale.com/tips/nginx/optimizing-nginx-for-serving-files-bigger-than-1gb/

proxy_max_temp_file_size 0;

So we're trying to figure out how to provide this config to Nginx via Kong. This Kong doc page suggests using a custom configuration template: https://getkong.org/docs/0.13.x/configuration/

Following those instructions we prepared a template file and invoked kong like this:

kong start -c kong.conf --nginx-conf custom_nginx.template

But at start we don't see the custom setting that we put into the template get propagated into the nginx conf file. Kong seems to create the Nginx config files at each startup. Is the answer right in front of us?? Do we have to modify the Kong LUA files? Thanks in advance.

chrisinmtown
  • 3,571
  • 3
  • 34
  • 43

3 Answers3

1

You can inject NGINX configurations by providing an envrionment variable to Kong. Here's a link to the docs.

For your use case, you should use :

export KONG_NGINX_HTTP_PROXY_MAX_TEMP_FILE_SIZE="0".

This will result in the following Nginx directive being added to the http block:

proxy_max_temp_file_size 0;

Here's also the NGINX docs of this directive.

Ilshidur
  • 1,461
  • 14
  • 11
0

this is kind of a stumper ... this is how I got it to work:

In your Dockerfile add a line to copy your custom template to your image:

COPY ./data/nginx-custom.template /usr/local/kong/nginx-custom.template

And COPY in a new docker-entrypoint.sh file

COPY ./docker-entrypoint.sh /docker-entrypoint.sh

And this CMD:

CMD ["/usr/local/openresty/nginx/sbin/nginx", "-c", "/usr/local/kong/nginx.conf", "-p", "/usr/local/kong/"]

the docker-entrypoint.sh file should look like this:

#!/bin/sh
set -e

# Disabling nginx daemon mode
export KONG_NGINX_DAEMON="off"

# Setting default prefix (override any existing variable)

export KONG_PREFIX="/usr/local/kong"

# Prepare Kong prefix
if [ "$1" = "/usr/local/openresty/nginx/sbin/nginx" ]; then
    kong prepare -p "/usr/local/kong" --nginx-conf "/usr/local/kong/nginx-custom.template"

fi

exec "$@"

that kong prepare command is creating the config file from your custom template, and then your CMD restarts nginx with your config.

I feel as if there should be a kong-specific way to reload, but kong reload doesn't do what I expect it to do ...

esperluette
  • 368
  • 4
  • 15
0

Late update. @esperluette's solution probably works. The hack we put in place consists of the following lines added to the docker startup CMD in a docker-compose config file. This tweaks the Nginx default template inside the docker image on creation of a container:

 sed -i -- 's/\ \ \ \ proxy_max_temp_file_size 0;//' /usr/local/share/lua/5.1/kong/templates/nginx_kong.lua
 sed -i -- '/server {/a\ \ \ \ proxy_max_temp_file_size 0;' /usr/local/share/lua/5.1/kong/templates/nginx_kong.lua

Not pretty.

chrisinmtown
  • 3,571
  • 3
  • 34
  • 43