安裝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


      

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章