Nginx+Lua搭建

Nginx作为后起之秀,Lua又号称是最快的脚本,大连回来之后想去看看Nginx+Lua,大概搭建了,但是不怎么会用。下面是搭建的过程,我采用了Openresty,这样方便点。

yum install openssl-devel readline-devel pcre-devel

git clone http://luajit.org/git/luajit-2.0.git
cd luajit-2.0/
make && make install
export LUAJIT_LIB=/usr/local/lib   
export LUAJIT_INC=/usr/local/include/luajit-2.0  

wget http://openresty.org/download/ngx_openresty-1.2.7.8.tar.gz
tar -zxvf ngx_openresty-1.2.7.8.tar.gz 
cd ngx_openresty-1.2.7.8
./configure --with-luajit
gmake && gmake install

PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH

接下来就是对nginx.conf的配置,最简单的“hello world”
location /test_lua {
	default_type text/html;
	content_by_lua '
	ngx.say("
              hello, world
        ") '; 
}

这时候访问下 http://ip/test_lua 就有了。

下面把 lua 单独当成脚本执行,在Nginx conf目录下 vim test.lua
[php]
ngx.say("hello,world")
[/php]

location /test_lua {
	default_type text/html;
	content_by_lua_file conf/test.lua; 
}

标签:none

评论已关闭