end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

install nginx v1.20 + lua-nginx-module to cent 7.9

https://blog.kozakana.net/2020/02/build-nginx-with-lua-nginx-module/

上記urlの写経です。

ちなみに、

  • 脆弱性があった場合、全部入りの openresty では対応が遅れると思い、nginx+lua-nginx-module を選択
  • 2021/12での最新は lua-nginx-module v0.10.20 やlua-resty-core v0.1.22 ですが、nginx の make 失敗に伴い v0.10.15 や v0.1.17 を使用。
$ cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

$ sudo yum install gcc gcc-c++
$ sudo yum install wget
$ sudo yum install perl-devel
$ sudo yum install zlib-devel
$ sudo yum install pcre-devel

$ sudo yum install lua-devel
$ /usr/bin/lua -v
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
$ sudo su -
# cd /usr/local/src
# wget https://github.com/openresty/luajit2/archive/v2.1-20211210.tar.gz
# tar -zxvf v2.1-20211210.tar.gz
# rm v2.1-20211210.tar.gz
# cd luajit2-2.1-20211210
# make
# make install
:
ln -sf luajit-2.1.0-beta3 /usr/local/bin/luajit
==== Successfully installed LuaJIT 2.1.0-beta3 to /usr/local ====
# cd /usr/local/src
# wget https://github.com/vision5/ngx_devel_kit/archive/v0.3.1.tar.gz
# tar -zxvf v0.3.1.tar.gz
# rm v0.3.1.tar.gz
# cd /usr/local/src
# wget https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
# tar -zxvf v0.10.15.tar.gz
# rm v0.10.15.tar.gz
# cd /usr/lib
# wget https://github.com/openresty/lua-resty-core/archive/v0.1.17.tar.gz
# tar -zxvf v0.1.17.tar.gz
# rm v0.1.17.tar.gz
# cd /usr/local/share/lua/5.1
# mkdir resty
# cd resty
# ln -s /usr/lib/lua-resty-core-0.1.17/lib/resty/core core
# ln -s /usr/lib/lua-resty-core-0.1.17/lib/resty/core.lua core.lua
# cd /usr/lib
# wget https://github.com/openresty/lua-resty-lrucache/archive/v0.09.tar.gz
# tar -zxvf v0.09.tar.gz
# rm v0.09.tar.gz
# cd /usr/local/share/lua/5.1/resty
# ln -s /usr/lib/lua-resty-lrucache-0.09/lib/resty/lrucache lrucache
# ln -s /usr/lib/lua-resty-lrucache-0.09/lib/resty/lrucache.lua lrucache.lua
$ cd /home/end0tknr/tmp

$ wget https://nginx.org/download/nginx-1.20.2.tar.gz
$ tar -xvf nginx-1.20.2.tar.gz

$ wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1m.tar.gz
$ tar -xvf openssl-1.1.1m.tar.gz

$ export LUAJIT_LIB=/usr/local/lib
$ export LUAJIT_INC=/usr/local/include/luajit-2.1

$ cd nginx-1.20.2
$ ./configure \
  --prefix=/home/end0tknr/local/nginx \
  --add-module=/usr/local/src/ngx_devel_kit-0.3.1 \
  --add-module=/usr/local/src/lua-nginx-module-0.10.15 \
  --with-http_ssl_module \
  --with-openssl=../openssl-1.1.1m
$ make
$ make install

$ sudo vi /etc/ld.so.conf
/usr/local/lib を行追加
$ sudo ldconfig
$ vi ~/local/nginx/conf/nginx.conf

server {
  listen       8080; # <- 80
  server_name  localhost;

  location / {
    content_by_lua_block {
      ngx.header.content_type = "text/html; charset=UTF-8"
      ngx.say("Hello, lua-nginx-module !")
    }
    # ↓ org
    #root   html;
    #index  index.html index.htm;
  }
  :
}