安装脚本
$ cat build.sh
#!/bin/bash
#
PCRE_DIR=$PWD/pcre-8.38
cd ngx_openresty-*
APPDIR=$HOME/s/apps/resty
LOGDIR=$HOME/s/logs/resty
./configure \
--prefix=$APPDIR \
--error-log-path=$LOGDIR/error.log \
--pid-path=$LOGDIR/resty.pid \
--lock-path=$LOGDIR/resty.lock \
--http-log-path=$LOGDIR/access.log \
--with-http_stub_status_module \
--with-pcre=$PCRE_DIR \
--http-client-body-temp-path=$LOGDIR/client/ \
--http-proxy-temp-path=$LOGDIR/proxy/ \
--http-fastcgi-temp-path=$LOGDIR/fastcgi/ \
--http-uwsgi-temp-path=$LOGDIR/uwsgi/ \
--http-scgi-temp-path=$LOGDIR/scgi/ \
--user=search \
--group=search
make && make install
# --without-pcre \
# --without-http_rewrite_module \
# --without-http_gzip_module \
搭建测试环境
mkdir $HOME/work/resty
cd $HOME/work/resty
mkdir logs/ conf/ lua/ lua/app/
$ cat conf/nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua '
ngx.say("<p>hello, world</p>")
';
}
location ~ ^/app/([-_a-zA-Z0-9/]+) {
set $path $1;
content_by_lua_file lua/app/$path.lua;
}
}
}
$ cat lua/app/hello.lua
ngx.say("Hello, Lua !")
$ cat nginx.sh
#!/bin/bash
#
cd $(dirname $0)
APPDIR=$(pwd)
export PATH=$HOME/s/apps/resty/nginx/sbin:$PATH
nginx -p $APPDIR/ -c conf/nginx.conf $@
# 启动nginx server
./nginx.sh
# 测试结果
wget -O- -q -d 127.0.0.1:8080
wget -O- -q -d 127.0.0.1:8080/app/hello