openresty 安装nginx和lua,openrestynginxlua
openresty 安装nginx和lua,openrestynginxlua
安装pcremkdir /usr/local/openresty
cd openresty
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
yum install -y gcc gcc-c++
./configure
make && make install
cd ..
安装openresty
yum install -y readline-devel pcre-devel openssl-devel gcc
wget http://openresty.org/download/ngx_openresty-1.7.7.2.tar.gz
tar -zxvf ngx_openresty-1.7.7.2.tar.gz
cd ngx_openresty-1.7.7.2/bundle/LuaJIT-2.1-20150120/
make clean && make && make install
ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
cd ..
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar zxvf 2.3.tar.gz
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar -zxvf v0.3.0.tar.gz
cd /usr/local/openresty/ngx_openresty-1.7.7.2
./configure --prefix=/usr/local/openresty --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2 --with-http_iconv_module --with-http_postgres_module --with-pcre-jit --with-pcre=../pcre-8.35
问题:
./configure: error: ngx_postgres addon was unable to detect version of the libpq library
解决:
yum install postgresql-devel
make && make install
cd /usr/local/openresty 可以查看到bin luajit lualib nginx等
部署实例
cd /usr
mkdir hello
vim hello.conf
server {
listen 80;
server_name _;
location /hello {
default_type 'text/html';
content_by_lua_file /usr/hello/lua/hello.lua;
}
}
:wq 保存
mkdir lua
vim hello.lua
ngx.say("hello world,this is slave1");
:wq 保存
cd /usr/local/openresty/nginx/conf
vim nginx.conf
在 http{
}中加入
lua_package_path "/usr/hello/lualib/?.lau;;";
lua_package_cpath "/usr/hello/lualib/?.so;;";
include /usr/hello/hello.conf;
:wq 保存退出
cp -rf /usr/local/openresty/lualib /usr/hello/
cd /usr/local/openresty/nginx/sbin
./nginx 回车
更改nginx配置后需要重新加载,命令为 ./nginx -s reload
然后在浏览器中访问 http://192.168.0.187/hello 即可看到hello world,this is slave1
评论暂时关闭