@dooy
2016-11-25T07:41:57.000000Z
字数 2497
阅读 270
Nginx 安装
| 软件 | 下载地址 |
|---|---|
| nginx | http://nginx.org/en/download.html |
| luajit 2.0 | http://luajit.org/download.html |
| ngx_devel_kit | https://github.com/simpl/ngx_devel_kit/tags |
| nginx_lua_module | https://github.com/openresty/lua-nginx-module/tags |
| cjson(luajit cjson) | http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz |
wget http://luajit.org/download/LuaJIT-2.0.4.tar.gztar xf LuaJIT-2.0.4.tar.gzcd LuaJIT-2.0.4make && make install
make前修改配置文件
vi Makefile
LUA_INCLUDE_DIR = $(PREFIX)/include/luajit-2.0
wget http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gztar -zvxf lua-cjson-2.1.0.tar.gzcd lua-cjson-2.1.0makemake install
解压 nginx ngx_devel_kit nginx_lua_module http-concat
cd到nginx目录编译
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz -O v0.2.19.tar.gzwget https://github.com/openresty/lua-nginx-module/archive/v0.10.2.tar.gz -O v0.10.2.tar.gzwget https://github.com/alibaba/nginx-http-concat/archive/master.zip -O nginx-http-concat-master.ziptar xvf v0.2.19.tar.gztar xvf v0.10.2.tar.gzunzip nginx-http-concat-master.zipcd nginx-1.8.0./configure --prefix=/usr/local/nginx/ --add-module=../ngx_devel_kit-0.2.19 --add-module=../lua-nginx-module-0.10.2 --add-module=../nginx-http-concat-master --with-http_ssl_module --with-http_stub_status_modulemake && make install
wget https://github.com/alibaba/nginx-http-concat/archive/master.zip -O nginx-http-concat-master.zipunzip nginx-http-concat-master.zipcd nginx-dir./configure --prefix=/usr/local/nginx/ --add-module=../nginx-http-concat-master --with-http_ssl_modulemake && make install
在 /usr/local/nginx/conf/nginx.conf 中加入下面的代码
location /hello {default_type 'text/plain';content_by_lua 'ngx.say("hello, lua")';}
重启nginx
执行 http://ip/hello
如果有 出现 hello,lua 说明就安装成功了
vim /usr/local/nginx/lua/checklogin.lua
function checkIslogin( str )str = ngx.unescape_uri(str);local gckey="111";local cjson = require "cjson"local sjon = cjson.new().decode( str );local nowkey= ngx.md5( string.format("%s%s%s", sjon.a, gckey, sjon.b));-- ngx.log(ngx.ERR, "do login ", nowkey )return nowkey==sjon.kendlocal isLogin= falsepcall( function(istr) isLogin= checkIslogin(istr) end , ngx.var.cookie_userinfo )if isLogin== false then--ngx.log(ngx.ERR, "do login ", ngx.var.cookie_userinfo )return ngx.exit(403)endreturn
在 http server location 配置
access_by_lua_file /usr/local/nginx/lua/checklogin.lua;
比如:
location /wangtocheck {default_type 'text/html';access_by_lua_file /usr/local/nginx/lua/checklogin.lua;}