官网:
CentOS
添加openresty
仓库
wget https://openresty.org/package/centos/openresty.repo
sudo mv openresty.repo /etc/yum.repos.d/
sudo yum check-update
安装openresty
软件包:
sudo yum install -y openresty
安装结束后默认位置是 /usr/local/openresty
启动nginx 遇到错误
./nginx: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
通过ldd 命令查看是缺少包
[root@test sbin]# ldd /usr/local/openresty/nginx/sbin/nginx
linux-vdso.so.1 => (0x00007ffc32bdb000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fb594101000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb593ee4000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fb593cad000)
libluajit-5.1.so.2 => /usr/local/openresty/luajit/lib/libluajit-5.1.so.2 (0x00007fb593c23000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb593920000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fb5936bf000)
libssl.so.1.1 => not found
libcrypto.so.1.1 => not found
libz.so.1 => /lib64/libz.so.1 (0x00007fb5934a8000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb5930e7000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb594319000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fb592ee3000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb592ccd000)
解决方案:
wget -c https://www.openssl.org/source/openssl-1.1.1s.tar.gz
tar -zxvf openssl-1.1.1s.tar.gz
cd openssl-1.1.1s/./config
make
make test (failed 2 tests)
sudo make install (on this moment you can't install python by pyenv)
sudo find / -name libssl.so.1.1
sudo ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
sudo find / -name libcrypto.so.1.1
sudo ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1
查看nginx版本
[root@test sbin]# ./nginx -v
nginx version: openresty/1.21.4.1
第一个lua脚本
在nginx.conf 中写入
location /lua {default_type text/html;
content_by_lua 'ngx.say("hello")';
}
获取Nginx uri中的单一变量
location /nginx_var {
default_type text/html;
content_by_lua_block {
ngx.say(ngx.var.arg_a)
}
}
获取Nginx uri中的所有变量
local uri_args = ngx.req.get_uri_args()
for k, v in pairs(uri_args) do
if type(v) == "table" then
ngx.say(k, " : ", table.concat(v, ", "), "<br/>")
else
ngx.say(k, ": ", v, "<br/>")
end
end
获取Nginx请求头信息
local headers = ngx.req.get_headers()
ngx.say("Host : ", headers["Host"], "<br/>")
ngx.say("user-agent : ", headers["user-agent"], "<br/>")
ngx.say("user-agent : ", headers.user_agent, "<br/>")
for k,v in pairs(headers) do
if type(v) == "table" then
ngx.say(k, " : ", table.concat(v, ","), "<br/>")
else
ngx.say(k, " : ", v, "<br/>")
end
end
获取post请求参数
ngx.req.read_body()
ngx.say("post args begin", "<br/>")
local post_args = ngx.req.get_post_args()
for k, v in pairs(post_args) do
if type(v) == "table" then
ngx.say(k, " : ", table.concat(v, ", "), "<br/>")
else
ngx.say(k, ": ", v, "<br/>")
end
end
http协议版本
ngx.say("ngx.req.http_version : ", ngx.req.http_version(), "<br/>")
请求方法
ngx.say("ngx.req.get_method : ", ngx.req.get_method(), "<br/>")
原始的请求头内容
ngx.say("ngx.req.raw_header : ", ngx.req.raw_header(), "<br/>")
body内容体
ngx.say("ngx.req.get_body_data() : ", ngx.req.get_body_data(), "<br/>")