Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot start 0.13 with custom template configuration - Bad argument #1 to 'compile_nginx_conf' #3384

Closed
IvanoffDan opened this issue Apr 9, 2018 · 2 comments

Comments

@IvanoffDan
Copy link

Summary

Hi all,

First of all, would like to thank all the maintainers of this repo for providing such an amazing tool that solves so many of our day-to-day problems.

We have been running Kong as a Docker container in our development environment.

I've been trying to upgrade from 0.12 to 0.13. Once I've started encountering errors related to the new template format I've swapped our custom template implementation and kong.conf with their default implementations (/templates/nginx_kong.lua and ./kong.conf.default). However, I'm still not being able to start kong.

Steps To Reproduce

  1. Have Docker installed
  2. Put default custom_nginx.template in your root directory
  3. Use Dockerfile and docker-compose.yml specified below
  4. docker compose build
  5. docker compose up

Additional Details & Logs

  • Kong version 0.13.0
  • Kong debug-level startup logs ($ kong start --vv)
kong_1            | /usr/local/share/lua/5.1/kong/cmd/start.lua:62: /usr/local/share/lua/5.1/kong/cmd/utils/prefix_handler.lua:240: bad argument #1 to 'compile_nginx_conf' (string expected, got nil)
kong_1            | stack traceback:
kong_1            |     [C]: in function 'error'
kong_1            |     /usr/local/share/lua/5.1/kong/cmd/start.lua:62: in function 'cmd_exec'
kong_1            |     /usr/local/share/lua/5.1/kong/cmd/init.lua:87: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:87>
kong_1            |     [C]: in function 'xpcall'
kong_1            |     /usr/local/share/lua/5.1/kong/cmd/init.lua:87: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:44>
kong_1            |     /usr/local/bin/kong:7: in function 'file_gen'
kong_1            |     init_worker_by_lua:54: in function <init_worker_by_lua:52>
kong_1            |     [C]: in function 'xpcall'
kong_1            |     init_worker_by_lua:61: in function <init_worker_by_lua:59>
kong_1            |
  • Dockerfile
FROM kong:0.13.0

WORKDIR /usr/local/kong

COPY ./custom_nginx.template ./custom_nginx.template
COPY ./kong.conf ./kong.conf

CMD kong check kong.conf && \
  kong start --run-migrations --conf ./kong.conf --nginx-conf ./custom_nginx.template -vv
  • docker-compose.yml
kong:
    build: kong/
    depends_on:
      - kong-database
    environment:
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
      - KONG_PG_DATABASE=kong
      - KONG_ADMIN_LISTEN=0.0.0.0:8001        
    expose:
      - 8000
      - 8001
      - 8443
      - 8444
    ports:
      - "8000:8000"
      - "8001:8001"
      - "8443:8443"
      - "8444:8444"
    volumes:
      - type: bind
        source: ./client/dist
        target: /www/data/public/
  • custom_nginx.template
charset UTF-8;
> if nginx_user then
user ${{NGINX_USER}};
> end
worker_processes ${{NGINX_WORKER_PROCESSES}};
daemon ${{NGINX_DAEMON}};
pid pids/nginx.pid;
error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};
> if nginx_optimizations then
worker_rlimit_nofile ${{WORKER_RLIMIT}};
> end
events {
> if nginx_optimizations then
    worker_connections ${{WORKER_CONNECTIONS}};
    multi_accept on;
> end
}

> if anonymous_reports then
${{SYSLOG_REPORTS}}
> end
error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};
> if nginx_optimizations then
>-- send_timeout 60s;          # default value
>-- keepalive_timeout 75s;     # default value
>-- client_body_timeout 60s;   # default value
>-- client_header_timeout 60s; # default value
>-- tcp_nopush on;             # disabled until benchmarked
>-- proxy_buffer_size 128k;    # disabled until benchmarked
>-- proxy_buffers 4 256k;      # disabled until benchmarked
>-- proxy_busy_buffers_size 256k; # disabled until benchmarked
>-- reset_timedout_connection on; # disabled until benchmarked
> end
client_max_body_size ${{CLIENT_MAX_BODY_SIZE}};
proxy_ssl_server_name on;
underscores_in_headers on;
lua_package_path '${{LUA_PACKAGE_PATH}};;';
lua_package_cpath '${{LUA_PACKAGE_CPATH}};;';
lua_socket_pool_size ${{LUA_SOCKET_POOL_SIZE}};
lua_max_running_timers 4096;
lua_max_pending_timers 16384;
lua_shared_dict kong                5m;
lua_shared_dict kong_cache          ${{MEM_CACHE_SIZE}};
lua_shared_dict kong_process_events 5m;
lua_shared_dict kong_cluster_events 5m;
lua_shared_dict kong_healthchecks   5m;
> if database == "cassandra" then
lua_shared_dict kong_cassandra      5m;
> end
lua_socket_log_errors off;
> if lua_ssl_trusted_certificate then
lua_ssl_trusted_certificate '${{LUA_SSL_TRUSTED_CERTIFICATE}}';
lua_ssl_verify_depth ${{LUA_SSL_VERIFY_DEPTH}};
> end
init_by_lua_block {
    kong = require 'kong'
    kong.init()
}
init_worker_by_lua_block {
    kong.init_worker()
}
> if #proxy_listeners > 0 then
upstream kong_upstream {
    server 0.0.0.1;
    balancer_by_lua_block {
        kong.balancer()
    }
    keepalive ${{UPSTREAM_KEEPALIVE}};
}
server {
    server_name kong;
> for i = 1, #proxy_listeners do
    listen $(proxy_listeners[i].listener);
> end
    error_page 400 404 408 411 412 413 414 417 /kong_error_handler;
    error_page 500 502 503 504 /kong_error_handler;
    access_log ${{PROXY_ACCESS_LOG}};
    error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};
    client_body_buffer_size ${{CLIENT_BODY_BUFFER_SIZE}};
> if proxy_ssl_enabled then
    ssl_certificate ${{SSL_CERT}};
    ssl_certificate_key ${{SSL_CERT_KEY}};
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_certificate_by_lua_block {
        kong.ssl_certificate()
    }
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ${{SSL_CIPHERS}};
> end
> if client_ssl then
    proxy_ssl_certificate ${{CLIENT_SSL_CERT}};
    proxy_ssl_certificate_key ${{CLIENT_SSL_CERT_KEY}};
> end
    real_ip_header     ${{REAL_IP_HEADER}};
    real_ip_recursive  ${{REAL_IP_RECURSIVE}};
> for i = 1, #trusted_ips do
    set_real_ip_from   $(trusted_ips[i]);
> end
    location / {
        set $upstream_host               '';
        set $upstream_upgrade            '';
        set $upstream_connection         '';
        set $upstream_scheme             '';
        set $upstream_uri                '';
        set $upstream_x_forwarded_for    '';
        set $upstream_x_forwarded_proto  '';
        set $upstream_x_forwarded_host   '';
        set $upstream_x_forwarded_port   '';
        rewrite_by_lua_block {
            kong.rewrite()
        }
        access_by_lua_block {
            kong.access()
        }
        proxy_http_version 1.1;
        proxy_set_header   Host              $upstream_host;
        proxy_set_header   Upgrade           $upstream_upgrade;
        proxy_set_header   Connection        $upstream_connection;
        proxy_set_header   X-Forwarded-For   $upstream_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $upstream_x_forwarded_proto;
        proxy_set_header   X-Forwarded-Host  $upstream_x_forwarded_host;
        proxy_set_header   X-Forwarded-Port  $upstream_x_forwarded_port;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_pass_header  Server;
        proxy_pass_header  Date;
        proxy_ssl_name     $upstream_host;
        proxy_pass         $upstream_scheme://kong_upstream$upstream_uri;
        header_filter_by_lua_block {
            kong.header_filter()
        }
        body_filter_by_lua_block {
            kong.body_filter()
        }
        log_by_lua_block {
            kong.log()
        }
    }
    location = /kong_error_handler {
        internal;
        content_by_lua_block {
            kong.handle_error()
        }
    }
}
> end
> if #admin_listeners > 0 then
server {
    server_name kong_admin;
> for i = 1, #admin_listeners do
    listen $(admin_listeners[i].listener);
> end
    access_log ${{ADMIN_ACCESS_LOG}};
    error_log ${{ADMIN_ERROR_LOG}} ${{LOG_LEVEL}};
    client_max_body_size 10m;
    client_body_buffer_size 10m;
> if admin_ssl_enabled then
    ssl_certificate ${{ADMIN_SSL_CERT}};
    ssl_certificate_key ${{ADMIN_SSL_CERT_KEY}};
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ${{SSL_CIPHERS}};
> end
    location / {
        default_type application/json;
        content_by_lua_block {
            kong.serve_admin_api()
        }
    }
    location /nginx_status {
        internal;
        access_log off;
        stub_status;
    }
    location /robots.txt {
        return 200 'User-agent: *\nDisallow: /';
    }
}
  • Operating System kong:0.13.0-alpine
@thibaultcha
Copy link
Member

Hi,

I haven't given your template a try to find out the root issue, but this is something that #3294 should fix in 0.13.1. Maybe if you apply the patch locally you would be able to see the error the Penlight template engine is complaining about.

Make sure the template is a single file with the kong part inlined into the main http block before feeding it to the prepare or start commands.

Btw, every major upgrade has nginx configuration changes, and a diff of the changes to apply to your custom template can always be found in the proper UPGRADE.md section (in the expandable bold section).

@IvanoffDan
Copy link
Author

Appreciate your quick reply. I've managed to make custom template to work by using this as a blueprint. I'm installing kong in development mode now to figure out what the actual error was.

I believe the issue can be closed because, as you've pointed out, #3294 will most likely resolve it by making template errors less cryptic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants