unknown directive "access_by_lua"
unknown directive "set_unescape_uri"javascript
之因此报错是缺乏nginx的三方插件,下面介绍安装nginx的第三方插件,插件不少直介绍三个html
方式一:java
下载 ngx_openresty,该集成包中有:Nginx,Lua或Luajit,ngx_lua,以及一些有用的Nginx第三方模块。linux
安装步骤:nginx
安装完成,我的建议第一种安装方便简单,另外这个版本还提供了不少的组件,安装不会出现错误。git
方式二:github
Ngx_lua手动编译进Nginx。
首先,个人 Nginx 安装路径为:/usr/local/nginx。
我将尝试编译的两个模块:echo,lua。
所须要的模块以下:
liujit http://luajit.org
lua http://www.lua.org
ngx_devel_kit https://github.com/simpl/ngx_devel_kit
echo-nginx-module https://github.com/agentzh/echo-nginx-module
lua-nginx-module https://github.com/chaoslawful/lua-nginx-module
安装步骤:
一、Luajit2.0.2(推荐)web
Java代码 算法
安装luacentos
tar-zxvf lua-5.2.0.tar.gz cd lua-5.2.0 make linux make install 完成安装. 若是遇到 lua.c:67:31: fatal error: readline/readline.h: No such file or directory 说明缺乏libreadline-dev依赖包 centos: yum install readline-devel debian: apt-get install libreadline-dev.
下面须要配置一下 luajit 或 lua 的环境变量(Nginx编译时须要):
Java代码
个人测试环境里,配置以下:
Java代码
二、安装 ngx_devel_kit (NDK) 模块
Java代码
下载完成后,将在 /usr/local/ 目录下生成子目录 ngx_devel_kit。
三、安装 lua-nginx-module 模块
Java代码
下载完成后,将在 /usr/local/ 目录下生成子目录 lua-nginx-module。
四、从新编译Nginx,须要注意编译顺序!
Java代码
注释:从新编译 Nginx 二进制,Nginx 须要 quit 再启动。而普通配置更新则 reload 便可:
kill -HUP `cat /path/nginx/logs/nginx.pid`
/usr/local/nginx/sbin/nginx -s reload
模块编译成功!
重启Nginx服务器!
在编译安装 Nginx 的第三方模块时,碰到一个错误:
/usr/local/nginx/sbin/ngxin -s reload
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
百事不得其解,后来Google之,发现了解决办法。
在 Nginx 编译时,须要指定 RPATH,加入下面选项便可:
./configure --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"
或者
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
五、测试Lua
在Nginx.conf 配置文件中,加入如下代码:
location /echo {
default_type 'text/plain';
echo 'hello echo';
}
location /lua {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
重启Nginx服务器:
/usr/local/nginx/sbin/nginx -s reload
使用curl测试:
[root@localhost] curl http://localhost/echo
hello echo
[root@localhost] curl http://localhost/lua
hello lua
测试结果代表,两个模块都安装成功!
简洁版
Java代码
另外一篇文章:http://sunjun041640.blog.163.com/blog/static/2562683220134931235857/
misc-nginx-module和lua-nginx-module插件具体文档可参考以下:
https://github.com/openresty/set-misc-nginx-module/tags
https://github.com/openresty/lua-nginx-module#installation
记录日志:
Java代码