Ubuntu 20.04: Install Lua dynamic module onto Nginx


Step 1: Install Nginx
apt-get install nginx

Result:

root@tutorialspots1:~# apt-get install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0
  libjpeg-turbo8 libjpeg8 libnginx-mod-http-image-filter
  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libtiff5
  libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 nginx-common
  nginx-core
Suggested packages:
  libgd-tools fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0
  libjpeg-turbo8 libjpeg8 libnginx-mod-http-image-filter
  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libtiff5
  libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 nginx
  nginx-common nginx-core
0 upgraded, 22 newly installed, 0 to remove and 100 not upgraded.
Need to get 3,183 kB of archives.
After this operation, 11.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Setting up libjbig0:amd64 (2.1-3.1build1) ...
Setting up libnginx-mod-http-xslt-filter (1.18.0-0ubuntu1.2) ...
Setting up libx11-data (2:1.6.9-2ubuntu1.2) ...
Setting up libwebp6:amd64 (0.6.1-2ubuntu0.20.04.1) ...
Setting up fonts-dejavu-core (2.37-1) ...
Setting up libjpeg-turbo8:amd64 (2.0.3-0ubuntu1.20.04.1) ...
Setting up libx11-6:amd64 (2:1.6.9-2ubuntu1.2) ...
Setting up libjpeg8:amd64 (8c-2ubuntu8) ...
Setting up libnginx-mod-mail (1.18.0-0ubuntu1.2) ...
Setting up libxpm4:amd64 (1:3.5.12-1) ...
Setting up fontconfig-config (2.13.1-2ubuntu3) ...
Setting up libnginx-mod-stream (1.18.0-0ubuntu1.2) ...
Setting up libtiff5:amd64 (4.1.0+git191117-2ubuntu0.20.04.2) ...
Setting up libfontconfig1:amd64 (2.13.1-2ubuntu3) ...
Setting up libgd3:amd64 (2.2.5-5.2ubuntu2.1) ...
Setting up libnginx-mod-http-image-filter (1.18.0-0ubuntu1.2) ...
Setting up nginx-core (1.18.0-0ubuntu1.2) ...
Setting up nginx (1.18.0-0ubuntu1.2) ...
Processing triggers for ufw (0.36-6ubuntu1) ...
Processing triggers for systemd (245.4-4ubuntu3.13) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

Step 2: download sources

cd /usr/local/src
# Downloading Nginx
NGINX_VERSION=$(nginx -v 2>&1 | awk '{print $3}' | awk -F/ '{print $2}')
wget https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz
# Downloading Lua
wget https://github.com/openresty/luajit2/archive/v2.1-20200102.tar.gz
# Downloading Nginx development kit
wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1.tar.gz
# Downloading Nginx Lua Module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
# Downloading Resty Core
wget https://github.com/openresty/lua-resty-core/archive/v0.1.17.tar.gz
# Downloading Resty LRU Cache
wget https://github.com/openresty/lua-resty-lrucache/archive/v0.09.tar.gz

Result:

root@tutorialspots1:~# cd /usr/local/src
root@tutorialspots1:/usr/local/src# # Downloading Nginx
root@tutorialspots1:/usr/local/src# NGINX_VERSION=$(nginx -v 2>&1 | awk '{print $3}' | awk -F/ '{print $2}')
root@tutorialspots1:/usr/local/src# wget https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz
--2022-04-09 07:54:23--  https://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 2a05:d014:edb:5704::6, 2a05:d014:edb:5702::6, 52.58.199.22, ...
Connecting to nginx.org (nginx.org)|2a05:d014:edb:5704::6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: ‘nginx-1.18.0.tar.gz’

nginx-1.18.0.tar.gz 100%[===================>]   1015K  2.27MB/s    in 0.4s

2022-04-09 07:54:24 (2.27 MB/s) - ‘nginx-1.18.0.tar.gz’ saved [1039530/1039530]
root@tutorialspots1:/usr/local/src# # Downloading Lua
root@tutorialspots1:/usr/local/src# wget https://github.com/openresty/luajit2/archive/v2.1-20200102.tar.gz
--2022-04-09 07:49:50--  https://github.com/openresty/luajit2/archive/v2.1-20200102.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/openresty/luajit2/tar.gz/refs/tags/v2.1-20200102 [following]
--2022-04-09 07:49:51--  https://codeload.github.com/openresty/luajit2/tar.gz/refs/tags/v2.1-20200102
Resolving codeload.github.com (codeload.github.com)... 140.82.121.10
Connecting to codeload.github.com (codeload.github.com)|140.82.121.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v2.1-20200102.tar.gz’

v2.1-20200102.tar.g     [   <=>              ]   1.04M  1.92MB/s    in 0.5s

2022-04-09 07:49:52 (1.92 MB/s) - ‘v2.1-20200102.tar.gz’ saved [1093752]

root@tutorialspots1:/usr/local/src# # Downloading Nginx development kit
root@tutorialspots1:/usr/local/src# wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1.tar.gz
--2022-04-09 07:49:52--  https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://github.com/vision5/ngx_devel_kit/archive/v0.3.1.tar.gz [following]
--2022-04-09 07:49:53--  https://github.com/vision5/ngx_devel_kit/archive/v0.3.1.tar.gz
Reusing existing connection to github.com:443.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/vision5/ngx_devel_kit/tar.gz/refs/tags/v0.3.1 [following]
--2022-04-09 07:49:53--  https://codeload.github.com/vision5/ngx_devel_kit/tar.gz/refs/tags/v0.3.1
Resolving codeload.github.com (codeload.github.com)... 140.82.121.10
Connecting to codeload.github.com (codeload.github.com)|140.82.121.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 66542 (65K) [application/x-gzip]
Saving to: ‘v0.3.1.tar.gz’

v0.3.1.tar.gz       100%[===================>]  64.98K   358KB/s    in 0.2s

2022-04-09 07:49:54 (358 KB/s) - ‘v0.3.1.tar.gz’ saved [66542/66542]

root@tutorialspots1:/usr/local/src# # Downloading Nginx Lua Module
root@tutorialspots1:/usr/local/src# wget https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
--2022-04-09 07:49:54--  https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/openresty/lua-nginx-module/tar.gz/refs/tags/v0.10.15 [following]
--2022-04-09 07:49:54--  https://codeload.github.com/openresty/lua-nginx-module/tar.gz/refs/tags/v0.10.15
Resolving codeload.github.com (codeload.github.com)... 140.82.121.10
Connecting to codeload.github.com (codeload.github.com)|140.82.121.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v0.10.15.tar.gz’

v0.10.15.tar.gz         [  <=>               ] 639.76K  1.38MB/s    in 0.5s

2022-04-09 07:49:55 (1.38 MB/s) - ‘v0.10.15.tar.gz’ saved [655110]

root@tutorialspots1:/usr/local/src# # Downloading Resty Core
root@tutorialspots1:/usr/local/src# wget https://github.com/openresty/lua-resty-core/archive/v0.1.17.tar.gz
--2022-04-09 07:49:55--  https://github.com/openresty/lua-resty-core/archive/v0.1.17.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/openresty/lua-resty-core/tar.gz/refs/tags/v0.1.17 [following]
--2022-04-09 07:49:56--  https://codeload.github.com/openresty/lua-resty-core/tar.gz/refs/tags/v0.1.17
Resolving codeload.github.com (codeload.github.com)... 140.82.121.10
Connecting to codeload.github.com (codeload.github.com)|140.82.121.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v0.1.17.tar.gz’

v0.1.17.tar.gz          [  <=>               ] 147.45K   544KB/s    in 0.3s

2022-04-09 07:49:57 (544 KB/s) - ‘v0.1.17.tar.gz’ saved [150985]

root@tutorialspots1:/usr/local/src# # Downloading Resty LRU Cache
root@tutorialspots1:/usr/local/src# wget https://github.com/openresty/lua-resty-lrucache/archive/v0.09.tar.gz
--2022-04-09 07:50:02--  https://github.com/openresty/lua-resty-lrucache/archive/v0.09.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/openresty/lua-resty-lrucache/tar.gz/refs/tags/v0.09 [following]
--2022-04-09 07:50:02--  https://codeload.github.com/openresty/lua-resty-lrucache/tar.gz/refs/tags/v0.09
Resolving codeload.github.com (codeload.github.com)... 140.82.121.10
Connecting to codeload.github.com (codeload.github.com)|140.82.121.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v0.09.tar.gz’

v0.09.tar.gz            [ <=>                ]  14.60K  --.-KB/s    in 0.09s

2022-04-09 07:50:03 (165 KB/s) - ‘v0.09.tar.gz’ saved [14954]

Step 3: install tar make gcc

apt-get install tar make gcc

Result:

root@tutorialspots1:/usr/local/src# apt-get install tar make gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
tar is already the newest version (1.30+dfsg-7ubuntu0.20.04.2).
tar set to manually installed.
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 gcc-9
  gcc-9-base libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0
  libcrypt-dev libctf-nobfd0 libctf0 libgcc-9-dev libgomp1 libisl22 libitm1
  liblsan0 libmpc3 libquadmath0 libtsan0 libubsan1 linux-libc-dev manpages-dev
Suggested packages:
  binutils-doc cpp-doc gcc-9-locales gcc-multilib autoconf automake libtool
  flex bison gdb gcc-doc gcc-9-multilib gcc-9-doc glibc-doc make-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 gcc gcc-9
  gcc-9-base libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0
  libcrypt-dev libctf-nobfd0 libctf0 libgcc-9-dev libgomp1 libisl22 libitm1
  liblsan0 libmpc3 libquadmath0 libtsan0 libubsan1 linux-libc-dev make
  manpages-dev
0 upgraded, 29 newly installed, 0 to remove and 34 not upgraded.
Need to get 34.2 MB of archives.
After this operation, 151 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 binutils-common amd64 2.34-6ubuntu1.3 [207 kB]
Get:2 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libbinutils amd64 2.34-6ubuntu1.3 [474 kB]
Get:3 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libctf-nobfd0 amd64 2.34-6ubuntu1.3 [47.4 kB]
Get:4 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libctf0 amd64 2.34-6ubuntu1.3 [46.6 kB]
Get:5 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 binutils-x86-64-linux-gnu amd64 2.34-6ubuntu1.3 [1,613 kB]
Get:6 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 binutils amd64 2.34-6ubuntu1.3 [3,380 B]
Get:7 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 gcc-9-base amd64 9.4.0-1ubuntu1~20.04.1 [19.4 kB]
Get:8 https://mirror.hetzner.com/ubuntu/packages focal/main amd64 libisl22 amd64 0.22.1-1 [592 kB]
Get:9 https://mirror.hetzner.com/ubuntu/packages focal/main amd64 libmpc3 amd64 1.1.0-1 [40.8 kB]
Get:10 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 cpp-9 amd64 9.4.0-1ubuntu1~20.04.1 [7,500 kB]
Get:11 https://mirror.hetzner.com/ubuntu/packages focal/main amd64 cpp amd64 4:9.3.0-1ubuntu2 [27.6 kB]
Get:12 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libcc1-0 amd64 10.3.0-1ubuntu1~20.04 [48.8 kB]
Get:13 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libgomp1 amd64 10.3.0-1ubuntu1~20.04 [102 kB]
Get:14 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libitm1 amd64 10.3.0-1ubuntu1~20.04 [26.2 kB]
Get:15 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libatomic1 amd64 10.3.0-1ubuntu1~20.04 [9,284 B]
Get:16 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libasan5 amd64 9.4.0-1ubuntu1~20.04.1 [2,751 kB]
Get:17 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 liblsan0 amd64 10.3.0-1ubuntu1~20.04 [835 kB]
Get:18 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libtsan0 amd64 10.3.0-1ubuntu1~20.04 [2,009 kB]
Get:19 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libubsan1 amd64 10.3.0-1ubuntu1~20.04 [784 kB]
Get:20 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libquadmath0 amd64 10.3.0-1ubuntu1~20.04 [146 kB]
Get:21 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libgcc-9-dev amd64 9.4.0-1ubuntu1~20.04.1 [2,359 kB]
Get:22 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 gcc-9 amd64 9.4.0-1ubuntu1~20.04.1 [8,274 kB]
Get:22 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 gcc-9 amd64 9.4.0-1ubuntu1~20.04.1 [8,274 kB]
Get:23 https://mirror.hetzner.com/ubuntu/packages focal/main amd64 gcc amd64 4:9.3.0-1ubuntu2 [5,208 B]
Get:24 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libc-dev-bin amd64 2.31-0ubuntu9.7 [71.6 kB]
Get:25 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 linux-libc-dev amd64 5.4.0-107.121 [1,115 kB]
Get:26 https://mirror.hetzner.com/ubuntu/packages focal/main amd64 libcrypt-dev amd64 1:4.4.10-10ubuntu4 [104 kB]
Get:27 https://mirror.hetzner.com/ubuntu/packages focal-updates/main amd64 libc6-dev amd64 2.31-0ubuntu9.7 [2,518 kB]
Get:28 https://mirror.hetzner.com/ubuntu/packages focal/main amd64 make amd64 4.2.1-1.2 [162 kB]
Get:29 https://mirror.hetzner.com/ubuntu/packages focal/main amd64 manpages-dev all 5.05-1 [2,266 kB]
Fetched 34.1 MB in 31s (1,091 kB/s)
Selecting previously unselected package binutils-common:amd64.
(Reading database ... 37796 files and directories currently installed.)
Preparing to unpack .../00-binutils-common_2.34-6ubuntu1.3_amd64.deb ...
Unpacking binutils-common:amd64 (2.34-6ubuntu1.3) ...
Selecting previously unselected package libbinutils:amd64.
Preparing to unpack .../01-libbinutils_2.34-6ubuntu1.3_amd64.deb ...
Unpacking libbinutils:amd64 (2.34-6ubuntu1.3) ...
Selecting previously unselected package libctf-nobfd0:amd64.
Preparing to unpack .../02-libctf-nobfd0_2.34-6ubuntu1.3_amd64.deb ...
Unpacking libctf-nobfd0:amd64 (2.34-6ubuntu1.3) ...
Selecting previously unselected package libctf0:amd64.
Preparing to unpack .../03-libctf0_2.34-6ubuntu1.3_amd64.deb ...
Unpacking libctf0:amd64 (2.34-6ubuntu1.3) ...
Selecting previously unselected package binutils-x86-64-linux-gnu.
Preparing to unpack .../04-binutils-x86-64-linux-gnu_2.34-6ubuntu1.3_amd64.deb ...
Unpacking binutils-x86-64-linux-gnu (2.34-6ubuntu1.3) ...
Selecting previously unselected package binutils.
Preparing to unpack .../05-binutils_2.34-6ubuntu1.3_amd64.deb ...
Unpacking binutils (2.34-6ubuntu1.3) ...
Selecting previously unselected package gcc-9-base:amd64.
Preparing to unpack .../06-gcc-9-base_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking gcc-9-base:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package libisl22:amd64.
Preparing to unpack .../07-libisl22_0.22.1-1_amd64.deb ...
Unpacking libisl22:amd64 (0.22.1-1) ...
Selecting previously unselected package libmpc3:amd64.
Preparing to unpack .../08-libmpc3_1.1.0-1_amd64.deb ...
Unpacking libmpc3:amd64 (1.1.0-1) ...
Selecting previously unselected package cpp-9.
Preparing to unpack .../09-cpp-9_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking cpp-9 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package cpp.
Preparing to unpack .../10-cpp_4%3a9.3.0-1ubuntu2_amd64.deb ...
Unpacking cpp (4:9.3.0-1ubuntu2) ...
Selecting previously unselected package libcc1-0:amd64.
Preparing to unpack .../11-libcc1-0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libcc1-0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libgomp1:amd64.
Preparing to unpack .../12-libgomp1_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libgomp1:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libitm1:amd64.
Preparing to unpack .../13-libitm1_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libitm1:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libatomic1:amd64.
Preparing to unpack .../14-libatomic1_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libatomic1:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libasan5:amd64.
Preparing to unpack .../15-libasan5_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking libasan5:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package liblsan0:amd64.
Preparing to unpack .../16-liblsan0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking liblsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libtsan0:amd64.
Preparing to unpack .../17-libtsan0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libtsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libubsan1:amd64.
Preparing to unpack .../18-libubsan1_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libubsan1:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libquadmath0:amd64.
Preparing to unpack .../19-libquadmath0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libquadmath0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libgcc-9-dev:amd64.
Preparing to unpack .../20-libgcc-9-dev_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking libgcc-9-dev:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package gcc-9.
Preparing to unpack .../21-gcc-9_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking gcc-9 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package gcc.
Preparing to unpack .../22-gcc_4%3a9.3.0-1ubuntu2_amd64.deb ...
Unpacking gcc (4:9.3.0-1ubuntu2) ...
Selecting previously unselected package libc-dev-bin.
Preparing to unpack .../23-libc-dev-bin_2.31-0ubuntu9.7_amd64.deb ...
Unpacking libc-dev-bin (2.31-0ubuntu9.7) ...
Selecting previously unselected package linux-libc-dev:amd64.
Preparing to unpack .../24-linux-libc-dev_5.4.0-107.121_amd64.deb ...
Unpacking linux-libc-dev:amd64 (5.4.0-107.121) ...
Selecting previously unselected package libcrypt-dev:amd64.
Preparing to unpack .../25-libcrypt-dev_1%3a4.4.10-10ubuntu4_amd64.deb ...
Unpacking libcrypt-dev:amd64 (1:4.4.10-10ubuntu4) ...
Selecting previously unselected package libc6-dev:amd64.
Preparing to unpack .../26-libc6-dev_2.31-0ubuntu9.7_amd64.deb ...
Unpacking libc6-dev:amd64 (2.31-0ubuntu9.7) ...
Selecting previously unselected package make.
Preparing to unpack .../27-make_4.2.1-1.2_amd64.deb ...
Unpacking make (4.2.1-1.2) ...
Selecting previously unselected package manpages-dev.
Preparing to unpack .../28-manpages-dev_5.05-1_all.deb ...
Unpacking manpages-dev (5.05-1) ...
Setting up manpages-dev (5.05-1) ...
Setting up binutils-common:amd64 (2.34-6ubuntu1.3) ...
Setting up linux-libc-dev:amd64 (5.4.0-107.121) ...
Setting up libctf-nobfd0:amd64 (2.34-6ubuntu1.3) ...
Setting up libgomp1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up make (4.2.1-1.2) ...
Setting up libquadmath0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libmpc3:amd64 (1.1.0-1) ...
Setting up libatomic1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libubsan1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libcrypt-dev:amd64 (1:4.4.10-10ubuntu4) ...
Setting up libisl22:amd64 (0.22.1-1) ...
Setting up libbinutils:amd64 (2.34-6ubuntu1.3) ...
Setting up libc-dev-bin (2.31-0ubuntu9.7) ...
Setting up libcc1-0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up liblsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libitm1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up gcc-9-base:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Setting up libtsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libctf0:amd64 (2.34-6ubuntu1.3) ...
Setting up libasan5:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Setting up cpp-9 (9.4.0-1ubuntu1~20.04.1) ...
Setting up libc6-dev:amd64 (2.31-0ubuntu9.7) ...
Setting up binutils-x86-64-linux-gnu (2.34-6ubuntu1.3) ...
Setting up binutils (2.34-6ubuntu1.3) ...
Setting up libgcc-9-dev:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Setting up cpp (4:9.3.0-1ubuntu2) ...
Setting up gcc-9 (9.4.0-1ubuntu1~20.04.1) ...
Setting up gcc (4:9.3.0-1ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...

Step 3 alternative (recommended):
sudo apt install build-essential tar

Step 3b: sudo apt install git

Step 4: decompress all .tar.gz files
find . -type f -name '*.tar.gz' -exec tar -xzf {} \;

Step 5: build Lua

cd luajit*
make
make install
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1

Result:

...
OK        Successfully built LuaJIT
make[1]: Leaving directory '/usr/local/src/luajit2-2.1-20200102/src'
==== Successfully built LuaJIT 2.1.0-beta3 ====
root@tutorialspots1:/usr/local/src/luajit2-2.1-20200102# make install
==== Installing LuaJIT 2.1.0-beta3 to /usr/local ====
mkdir -p /usr/local/bin /usr/local/lib /usr/local/include/luajit-2.1 /usr/local/share/man/man1 /usr/local/lib/pkgconfig /usr/local/share/luajit-2.1.0-beta3/jit /usr/local/share/lua/5.1 /usr/local/lib/lua/5.1
cd src && install -m 0755 luajit /usr/local/bin/luajit-2.1.0-beta3
cd src && test -f libluajit.a && install -m 0644 libluajit.a /usr/local/lib/libluajit-5.1.a || :
rm -f /usr/local/lib/libluajit-5.1.so.2.1.0 /usr/local/lib/libluajit-5.1.so /usr/local/lib/libluajit-5.1.so.2
cd src && test -f libluajit.so && \
  install -m 0755 libluajit.so /usr/local/lib/libluajit-5.1.so.2.1.0 && \
  ldconfig -n /usr/local/lib && \
  ln -sf libluajit-5.1.so.2.1.0 /usr/local/lib/libluajit-5.1.so && \
  ln -sf libluajit-5.1.so.2.1.0 /usr/local/lib/libluajit-5.1.so.2 || :
cd etc && install -m 0644 luajit.1 /usr/local/share/man/man1
cd etc && sed -e "s|^prefix=.*|prefix=/usr/local|" -e "s|^multilib=.*|multilib=lib|" luajit.pc > luajit.pc.tmp && \
  install -m 0644 luajit.pc.tmp /usr/local/lib/pkgconfig/luajit.pc && \
  rm -f luajit.pc.tmp
cd src && install -m 0644 lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h /usr/local/include/luajit-2.1
cd src/jit && install -m 0644 bc.lua bcsave.lua dump.lua p.lua v.lua zone.lua dis_x86.lua dis_x64.lua dis_arm.lua dis_arm64.lua dis_arm64be.lua dis_ppc.lua dis_mips.lua dis_mipsel.lua dis_mips64.lua dis_mips64el.lua vmdef.lua /usr/local/share/luajit-2.1.0-beta3/jit
ln -sf luajit-2.1.0-beta3 /usr/local/bin/luajit
==== Successfully installed LuaJIT 2.1.0-beta3 to /usr/local ====
root@tutorialspots1:/usr/local/src/luajit2-2.1-20200102# export LUAJIT_LIB=/usr/local/lib
root@tutorialspots1:/usr/local/src/luajit2-2.1-20200102# export LUAJIT_INC=/usr/local/include/luajit-2.1

Step 6: Install Resty Core

cd ../lua-resty-core*
make install

Result:

root@tutorialspots1:/usr/local/src/luajit2-2.1-20200102# export LUAJIT_INC=/usr/local/include/luajit-2.1
root@tutorialspots1:/usr/local/src/luajit2-2.1-20200102# cd ../lua-resty-core*
root@tutorialspots1:/usr/local/src/lua-resty-core-0.1.17# make install
install -d /usr/local/lib/lua//resty/core/
install -d /usr/local/lib/lua//ngx/
install -d /usr/local/lib/lua//ngx/ssl
install lib/resty/*.lua /usr/local/lib/lua//resty/
install lib/resty/core/*.lua /usr/local/lib/lua//resty/core/
install lib/ngx/*.lua /usr/local/lib/lua//ngx/
install lib/ngx/ssl/*.lua /usr/local/lib/lua//ngx/ssl/

Step 7: Install Resty LRU Cache

cd ../lua-resty-lrucache*
make install

Result:

root@tutorialspots1:/usr/local/src/lua-resty-core-0.1.17# cd ../lua-resty-lrucache*
root@tutorialspots1:/usr/local/src/lua-resty-lrucache-0.09# make install
install -d //usr/local/lib/lua//resty/lrucache
install lib/resty/*.lua //usr/local/lib/lua//resty/
install lib/resty/lrucache/*.lua //usr/local/lib/lua//resty/lrucache/

Step 8:
apt-get install -y libpcre3-dev libaio-dev libgd-dev libxslt1-dev librust-openssl-dev

Step 9: Configure and build dynamic module

cd ..
rm *.tar.gz
cd nginx*
NGINX_CONFIGURE_ARGUMENTS=$(echo $(nginx -V 2>&1) | sed -nr '/configure arguments:/ s/.*configure arguments:([^"]+).*/\1/p'|sed 's/--with-ipv6 //g'|sed 's/-Wl,-z,relro -Wl,-z,now -specs=\/usr\/lib\/rpm\/redhat\/redhat-hardened-ld -Wl,-E/-Wl,-rpath,\/usr\/local\/lib/g')
eval "CFLAGS=-Wno-error ./configure --add-dynamic-module=../ngx_devel_kit-0.3.1 --add-dynamic-module=../lua-nginx-module-0.10.15 $NGINX_CONFIGURE_ARGUMENTS"

Result:

...
Configuration summary
  + using threads
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/share/nginx"
  nginx binary file: "/usr/share/nginx/sbin/nginx"
  nginx modules path: "/usr/lib/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/body"
  nginx http proxy temporary files: "/var/lib/nginx/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
  nginx http uwsgi temporary files: "/var/lib/nginx/uwsgi"
  nginx http scgi temporary files: "/var/lib/nginx/scgi"
...

make modules

Result:

...
cc -o objs/ngx_stream_module.so \
objs/src/stream/ngx_stream.o \
objs/src/stream/ngx_stream_variables.o \
objs/src/stream/ngx_stream_script.o \
objs/src/stream/ngx_stream_handler.o \
objs/src/stream/ngx_stream_core_module.o \
objs/src/stream/ngx_stream_log_module.o \
objs/src/stream/ngx_stream_proxy_module.o \
objs/src/stream/ngx_stream_upstream.o \
objs/src/stream/ngx_stream_upstream_round_robin.o \
objs/src/stream/ngx_stream_write_filter_module.o \
objs/src/stream/ngx_stream_ssl_module.o \
objs/src/stream/ngx_stream_limit_conn_module.o \
objs/src/stream/ngx_stream_access_module.o \
objs/src/stream/ngx_stream_geo_module.o \
objs/src/stream/ngx_stream_map_module.o \
objs/src/stream/ngx_stream_split_clients_module.o \
objs/src/stream/ngx_stream_return_module.o \
objs/src/stream/ngx_stream_upstream_hash_module.o \
objs/src/stream/ngx_stream_upstream_least_conn_module.o \
objs/src/stream/ngx_stream_upstream_random_module.o \
objs/src/stream/ngx_stream_upstream_zone_module.o \
objs/ngx_stream_module_modules.o \
-L/usr/local/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC \
-shared
make[1]: Leaving directory '/usr/local/src/nginx-1.18.0'

Step 10: Copy modules to modules-path

cp objs/*.so /usr/lib/nginx/modules

Step 11: Configure to load these modules configuration

echo -e "load_module /usr/lib/nginx/modules/ndk_http_module.so;\nload_module /usr/lib/nginx/modules/ngx_http_lua_module.so;" > /etc/nginx/modules-enabled/lua.conf

Step 12: enable openresty-core

Make file /etc/nginx/conf.d/openresty.conf

With content:

lua_package_path "/usr/local/lib/lua/?.lua;;";
 
init_by_lua_block {
    require "resty.core"
    collectgarbage("collect")  -- just to collect any garbage
}

or use command line:

echo -e "lua_package_path \"/usr/local/share/lua/?.lua;/usr/local/lib/lua/?.lua;;\";\nlua_package_cpath \"/usr/local/lib/lua/?.so;;\";\ninit_by_lua_block {\nrequire \"resty.core\"\ncollectgarbage("collect")  -- just to collect any garbage\n}" > /etc/nginx/conf.d/openresty.conf

Step 13: nginx

sudo systemctl restart nginx

Recent search terms:

  • install lua nginx from source
  • nginx lua install sources
  • внтфьшс кщще днгф

Leave a Reply