安装openresty

安装openresty
#!/base/bin
APPDIR=/data/app
mkdir -p $APPDIR

# 设置APPDIR为环境变量,因为其它模块安装的时候需要用到这个变量
export APPDIR

UPROFILE=/etc/profile

yum install -y gcc-c++

#当前脚本所在的目录(必须与openresty-1.2.8.6.tar.gz为同一个目录)
WORKDIR=$PWD

#oprenresty安装目录
DSTDIR=$APPDIR/openresty

#VERSION=1.2.7.8
VERSION=1.2.8.6
SRCTAR=ngx_openresty-$VERSION.tar.gz
SRCDIR=ngx_openresty-$VERSION

# 安装工具
echo "install tools ..."
yum install -y readline-devel pcre-devel openssl-devel

# 切换到当前目录
cd $WORKDIR
echo "install ngx_openresty ..."
sleep 1

# 避免脚本目录已经存在
rm -rf $SRCDIR

# 解压安装目录
tar xfz $SRCTAR

# 切换到脚本安装目录
cd $SRCDIR

# 创建temp目录
rm -rf $APPDIR/temp
mkdir -p $APPDIR/temp

#--with-http_postgres_module
./configure --with-ld-opt="-Wl,-rpath,/usr/local/lib" \
            --prefix=$APPDIR/openresty \

            # temp相对路径为openresty的安装目录,即为与openresty的安装目录为同一级目录
            # 需要先创建temp目录,编译不通过
            --http-client-body-temp-path=temp/client_body_temp  \
            --http-proxy-temp-path=temp/proxy_temp  \
            --http-fastcgi-temp-path=temp/fastcgi_temp  \
            --http-uwsgi-temp-path=temp/uwsgi_temp  \
            --http-scgi-temp-path=temp/scgi_temp  \
            --with-http_stub_status_module \
            --with-luajit \
            --with-http_iconv_module || exit $? 

cd $SRCDIR
make -j4 || exit $?

make install

# 设置PATH路径
echo ' ' >> $UPROFILE 
echo '#add nginx bin path' >> $UPROFILE 
echo "export PATH=$APPDIR/openresty/nginx/sbin:$PATH" >> $UPROFILE 
source $UPROFILE

echo Done


管理openresty  启动nginx的脚本:

注意:这里设置,该nginx启动脚本和nginx配置在同一个目录。

#!/bin/bash

workdir=$(dirname $(readlink -f $0))

conffile=$workdir/conf/nginx.conf

cmd=$1
echo "admin path:$workdir"
echo "your CMD:$cmd"

if [ "$cmd" == "start" ]; then
    nginx -p $workdir -c $conffile  
elif [ "$cmd" == "stop" ]; then
    nginx -p $workdir -c $conffile  -s stop 
elif [ "$cmd" == "quit" ]; then
    nginx -p $workdir -c $conffile  -s quit 
elif [ "$cmd" == "restart" ]; then
    nginx -p $workdir -c $conffile  -s stop 
    sleep 2
    nginx -p $workdir -c $conffile  
elif [ "$cmd" == "reload" ]; then
    nginx -p $workdir -c $conffile  -s reload 
elif [ "$cmd" == "test" ]; then
    nginx -p $workdir -c $conffile  -s test 
else
    echo "usage: ./admin.sh start|stop|quit|restart|reload|test"
fi

if [ $? -eq 0 ]; then
    echo ":::Done"
else
    echo ":::Failed"
fi

启动nginx的时候,需要注意两点:

(1)启动选项 “-c” 可以指定配置文件,nginx可以根据不同的配置文件,开启多个进程,但必须监听不同的端口。

 (2)启动选项 “-d”可以指定nginx的工作目录,这个很重要。在openrest HttpLuaModule这个关键的模块中,很多指令指定的路径,就是以nginx的工作目录为相对路径!


lua_package_path
syntax: lua_package_path <lua-style-path-str>
default: The content of LUA_PATH environ variable or Lua's compiled-in defaults.(默认为LUA_PATH环境变量或者是Lua的编译目录)
context: http
Sets the Lua module search path used by scripts specified by set_by_lua, content_by_lua and others. The path string is in standard Lua path form, and ;; can be used to stand for the original search paths.
As from the v0.5.0rc29 release, the special notation $prefix or ${prefix} can be used in the search path string to indicate the path of the server prefix usuallydetermined by the -p PATH command-line option while starting the Nginx server.  (nginx开启时指定的目录)

类似的还有如下指令:
lua_package_cpath, init_by_lua_file, set_by_lua_file, content_by_lua_file,rewrite_by_lua_file等

如果需要模拟http请求,可以使用库:https://github.com/liseen/lua-resty-http


      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值