# Change Nginx inside

**URL:** <https://discuss.konghq.com/t/change-nginx-inside/741>\
**Category:** Questions\
**Created:** [March 28, 2018, 1:38pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741 "2018-03-28T13:38:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![CatWithTail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/catwithtail/32/266_2.png) [@CatWithTail](https://discuss.konghq.com/u/CatWithTail)\
**Post date:** [March 28, 2018, 1:38pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741/1 "2018-03-28T13:38:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jeremyjpj0916](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/jeremyjpj0916/32/1388_2.png) [@jeremyjpj0916](https://discuss.konghq.com/u/jeremyjpj0916)\
**Post date:** [March 28, 2018, 5:30pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741/2 "2018-03-28T17:30:03Z")

</div>

Custom templates is how yah do it - [https://getkong.org/docs/0.13.x/configuration/#custom-nginx-configuration](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.

---

<div class="post-metadata">

**Author:** ![CatWithTail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/catwithtail/32/266_2.png) [@CatWithTail](https://discuss.konghq.com/u/CatWithTail)\
**Post date:** [March 29, 2018, 8:42am UTC](https://discuss.konghq.com/t/change-nginx-inside/741/3 "2018-03-29T08:42:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bungle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/bungle/32/13_2.png) [@bungle](https://discuss.konghq.com/u/bungle)\
**Post date:** [March 29, 2018, 10:55am UTC](https://discuss.konghq.com/t/change-nginx-inside/741/4 "2018-03-29T10:55:18Z")

</div>

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](https://github.com/Kong/kong/blob/master/kong/meta.lua#L21)

But then you are on your own.

---

<div class="post-metadata">

**Author:** ![CatWithTail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/catwithtail/32/266_2.png) [@CatWithTail](https://discuss.konghq.com/u/CatWithTail)\
**Post date:** [March 29, 2018, 2:48pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741/5 "2018-03-29T14:48:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CatWithTail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/catwithtail/32/266_2.png) [@CatWithTail](https://discuss.konghq.com/u/CatWithTail)\
**Post date:** [March 29, 2018, 4:38pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741/6 "2018-03-29T16:38:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bungle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/bungle/32/13_2.png) [@bungle](https://discuss.konghq.com/u/bungle)\
**Post date:** [March 29, 2018, 9:00pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741/7 "2018-03-29T21:00:11Z")

</div>

```auto
#!/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?

---

<div class="post-metadata">

**Author:** ![CatWithTail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/catwithtail/32/266_2.png) [@CatWithTail](https://discuss.konghq.com/u/CatWithTail)\
**Post date:** [March 30, 2018, 12:17pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741/8 "2018-03-30T12:17:51Z")

</div>

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_

---

<div class="post-metadata">

**Author:** ![CatWithTail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/catwithtail/32/266_2.png) [@CatWithTail](https://discuss.konghq.com/u/CatWithTail)\
**Post date:** [April 3, 2018, 12:55pm UTC](https://discuss.konghq.com/t/change-nginx-inside/741/9 "2018-04-03T12:55:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![CatWithTail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/catwithtail/32/266_2.png) [@CatWithTail](https://discuss.konghq.com/u/CatWithTail)\
**Post date:** [April 5, 2018, 10:39am UTC](https://discuss.konghq.com/t/change-nginx-inside/741/10 "2018-04-05T10:39:57Z")

</div>

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