在 Mac OS X(10.8)上安装 nginx + lua-nginx-module
搭建 nginx + lua-nginx-module 的环境设置。
我想使用nginx和lua-nginx-module做些事情,但不想再麻烦地在安装了Ubuntu的虚拟机上做,所以我在Mac OS X(10.8)上尝试了环境搭建。
在Mac OS X上进行环境配置。
在安装nginx时,需要安装PCRE和LuaJIT,可以使用homebrew来进行安装。虽然也可以使用Lua,但本次我们选择LuaJIT。
brew install pcre
brew install luajit
安装nginx和lua-nginx-module。
如果通过正式文件确认步骤,可以看到需要nginx_devel_kit和ngx_lua。
关于nginx,我们可以使用最近发布的nginx1.4.0。
进行git克隆操作,或者进行git切换操作。
> mkdir -p /usr/local/sandbox/nginx_lua_module
> cd /usr/local/sandbox/nginx_lua_module
>
> git clone git://github.com/simpl/ngx_devel_kit.git
> git clone git://github.com/chaoslawful/lua-nginx-module.git
> curl -O http://nginx.org/download/nginx-1.4.0.tar.gz
>
> tar -xvzf nginx-1.4.0.tar.gz
>
> cd ngx_devel_kit
> git checkout -b v0.2.18 v0.2.18
> cd ../lua-nginx-module
> git checkout -b v0.8.1 v0.8.1
> cd ../nginx-1.4.0
设置LuaJIT库文件和头文件路径。
> export LUAJIT_LIB="`brew --cellar luajit`/2.0.1/lib"
> export LUAJIT_INC="`brew --cellar luajit`/2.0.1/include/luajit-2.0"
准备构建nginx。
因为我是使用Homebrew来安装pcre的,所以需要指定CFLAGS和库的链接。
> mkdir -p /usr/local/nginx-1.4.0
> ./configure --prefix=/usr/local/nginx-1.4.0 \
> --add-module=/usr/local/sandbox/nginx_lua_module/ngx_devel_kit \
> --add-module=/usr/local/sandbox/nginx_lua_module/lua-nginx-module \
> --with-cc-opt='-O0 -I/usr/local/Cellar/pcre/8.32/include' \
> --with-ld-opt='-L/usr/local/Cellar/pcre/8.32/lib'
如果configure脚本通过,则进行编译。
> make -j2
> make install
开机测试
当构建成功并且安装完成后,进行启动测试。
sudo /usr/local/nginx-1.4.0/sbin/nginx
访问 http://localhost/。

好的。
确认lua-nginx-module是否正常工作
可以保留或编辑现有的nginx.conf文件的最基本设置,并进行操作确认。
> cd /usr/local/nginx-1.4.0/conf
> vi nginx.conf
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log logs/access.log;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
access_log logs/host.access.log;
location / {
root html;
index index.html index.htm;
}
location /lua-test {
default_type 'text/plain';
content_by_lua "ngx.say('Hello,world!')";
}
}
}
尝试访问新添加的/lua-test。

确认动作OK。
现在可以玩了。