Change Nginx inside

Hi!
I want to change Nginx inside kong OSS. My suggestion is: if I will build nginx with all parameters from
$# /usr/local/openresty/nginx/sbin/nginx -V
and if I will install my new built nginx into /usr/local/openresty/nginx/sbin instead of old nginx, (old nginx will be renamed to nginx.origin)
all should work fine.

So, that suggestion is totally wrong.
kong start didn’t work.
Do anybody something like that? How can I change nginx?

Custom templates is how yah do it - https://getkong.org/docs/0.13.x/configuration/#custom-nginx-configuration

Command such as:
kong prepare -p “/usr/local/kong” --nginx-conf “/usr/local/kong/optum_nginx.template”

where optum_nginx.template is your own home brew nginx config.

Hi!
Sorry, but i need nginx packet. Not only configuration.

Was it so that kong start didn’t work because you didn’t have supported version of nginx? If so, you need to change this file: https://github.com/Kong/kong/blob/master/kong/meta.lua#L21

But then you are on your own.

1 Like

Thank you! I gonna try to use some of this version now.

No, looks like the problem in some different place.

$# kong start
/usr/local/bin/kong:1: unexpected symbol near ‘#’

Can you tell me how do you preparing nginx for kong?

#!/usr/bin/env resty

This is the first line in that. Do you have /usr/bin/env and resty command available? And what shell (something else than Bash) are you using? And what OS are you using?

I using bash over Ubuntu 16.04
For testing, in
/usr/local/openresty/nginx/sbin
I made
mv nginx nginx.origin
and after that, I tried to run kong without success. When I moved the file back - kong works fine. But, with my nginx something went wrong.
About my nginx:
~# nginx -V
nginx version: nginx/1.12.2
_built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) _
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --with-cc-opt=-O2 --add-module=…/ngx_devel_kit --add-module=…/echo-nginx-module --add-module=…/xss-nginx-module-0.05 --add-module=…/ngx_coolkit-0.2rc3 --add-module=…/set-misc-nginx-module --add-module=…/form-input-nginx-module --add-module=…/encrypted-session-nginx-module --add-module=…/srcache-nginx-module --add-module=…/lua-nginx-module --add-module=…/lua-upstream-nginx-module --add-module=…/headers-more-nginx-module-0.32 --add-module=…/array-var-nginx-module --add-module=…/memc-nginx-module --add-module=…/redis2-nginx-module --add-module=…/ngx_http_redis-0.3.7 --add-module=…/rds-json-nginx-module --add-module=…/rds-csv-nginx-module --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre=…/pcre-8.39 --with-pcre-jit --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module

~# whereis nginx
nginx: /usr/sbin/nginx.origin /usr/sbin/nginx /usr/sbin/nginx.old /usr/lib/nginx /etc/nginx /usr/local/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

So:

    #!/bin/bash

    WorkDir='/usr/local/src/nginx'

    mkdir $WorkDir
     cd $WorkDir

    wget [https://nginx.ru/download/nginx-1.12.2.tar.gz]
     tar xfv nginx-1.12.2.tar.gz
     git clone [https://github.com/simplresty/ngx_devel_kit.git]
     git clone [https://github.com/openresty/echo-nginx-module.git]
     wget [https://github.com/openresty/xss-nginx-module/archive/v0.05.tar.gz]
     tar xfv v0.05.tar.gz
     wget [https://github.com/FRiCKLE/ngx_coolkit/archive/0.2rc3.tar.gz]
     tar xvf 0.2rc3.tar.gz
     git clone [https://github.com/openresty/set-misc-nginx-module.git]
     git clone [https://github.com/calio/form-input-nginx-module.git]
     git clone [https://github.com/openresty/encrypted-session-nginx-module.git]
     git clone [https://github.com/openresty/srcache-nginx-module.git]
     git clone [https://github.com/openresty/lua-nginx-module.git]
     git clone [https://github.com/openresty/lua-upstream-nginx-module.git]
     wget [https://github.com/openresty/headers-more-nginx-module/archive/v0.32.tar.gz] ; tar xfv v0.32.t*
     git clone [https://github.com/openresty/array-var-nginx-module.git]
     git clone [https://github.com/openresty/memc-nginx-module.git]
     git clone [https://github.com/openresty/redis2-nginx-module.git]
     wget [https://people.freebsd.org/~osa/ngx_http_redis-0.3.7.tar.gz]
     tar xfv ngx_http_redis-0.3.7.tar.gz
     git clone [https://github.com/openresty/rds-json-nginx-module.git]
     git clone [https://github.com/openresty/rds-csv-nginx-module.git]

    wget [https://www.openssl.org/source/openssl-1.0.2l.tar.gz]
     tar xvf openssl-1.0.2l.tar.gz

    wget [https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz]
     tar xfv pcre-8.39.tar.gz

    git clone [http://luajit.org/git/luajit-2.0.git]
     cd $WorkDir/luajit-2.0
     make
     sudo make install
     ln -s /usr/local/lib/libluajit-5.1.so.2.0.3 /usr/lib/libluajit-5.1.so.2

    cd $WorkDir
     export LUAJIT_LIB=/usr/lib
     export LUAJIT_INC=$WorkDir/luajit-2.0/src

    cd $WorkDir/nginx-1.12.2

    ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-cc-opt=-O2 --add-module=../ngx_devel_kit --add-module=../echo-nginx-module --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module --add-module=../form-input-nginx-module --add-module=../encrypted-session-nginx-module --add-module=../srcache-nginx-module --add-module=../lua-nginx-module --add-module=../lua-upstream-nginx-module --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module --add-module=../memc-nginx-module --add-module=../redis2-nginx-module --add-module=../ngx_http_redis-0.3.7 --add-module=../rds-json-nginx-module --add-module=../rds-csv-nginx-module --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre=../pcre-8.39 --with-pcre-jit --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module

This script will prepare nginx.

In file

/usr/local/share/lua/5.1/kong/meta.lua
we must to add our nginx version
in file

/usr/local/share/lua/5.1/kong/cmd/utils/nginx_signals.lua
we need to remove “openresty” part from version check string.

Also, we need to add some libs from here:

 git clone https://github.com/openresty/lua-resty-dns.git
 git clone https://github.com/openresty/lua-resty-core.git 
 git clone https://github.com/mpx/lua-cjson.git
 git clone https://github.com/openresty/lua-cjson.git
 git clone https://github.com/openresty/lua-cjson.git
 git clone https://github.com/openresty/lua-resty-string.git

And it works. So, how I can test it?

I found tests on GitHub. All works. Thank all.