nginx + ngx_lua安装测试
2014-02-14 15:58
513 查看
nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.nginx以高并发而知名,lua脚本轻便,两者的搭配堪称完美.接下来请看如何安装nginx + ngx_lua模块.以及最后来个简单的测试.
由于已经安装了nginx,所以需要重新编译,要保留原来安装的模块。
系统环境:centos/redhat
安装前准备好如下软件包
· nginx 地址:http://www.nginx.org
· luajit 地址:http://luajit.org/download.html
· HttpLuaModule 地址:http://wiki.nginx.org/HttpLuaModule
1. 下载安装LuaJIT
2. 下载准备nginx lua模块
3. 安装nginx
3.1 安装
3.1 常见错误
4. nginx lua配置
nginx配置文件加入如下配置:
5. 启动测试
5.1 启动nginx
5.2 访问测试
view source
print?
由于已经安装了nginx,所以需要重新编译,要保留原来安装的模块。
1.wget http://labs.frickle.com/files/ngx_cache_purge-2.0.tar.gz tar -zxvf ngx_cache_purge-2.0.tar.gz cd /data0/software/nginx-1.1.10 2.查看nginx编译安装时的命令,安装了哪些模块 /usr/local/webserver/nginx/sbin/nginx -V 3.加入需要安装的模块,重新编译 ./configure --user=www --group=www --add-module=../ngx_cache_purge-2.0 --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module make,不要make install会覆盖 make 4. 替换nginx二进制文件: cp /usr/local/webserver/nginx/sbin/nginx /usr/local/webserver/nginx/sbin/nginx.bak cp ./objs/nginx /usr/local/webserver/nginx/sbin/ (如果出现 “nginx正在忙的提示” 先停止nginx运行 <pre class="brush:php; toolbar: true; auto-links: false;">/usr/local/webserver/nginx/sbin/nginx -s stop </pre> <span></span>) 5.启动nginx /usr/local/webserver/nginx/sbin/nginx
系统环境:centos/redhat
安装前准备好如下软件包
· nginx 地址:http://www.nginx.org
· luajit 地址:http://luajit.org/download.html
· HttpLuaModule 地址:http://wiki.nginx.org/HttpLuaModule
1. 下载安装LuaJIT
# cd /usr/local/src |
# wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz |
# tar -xzvf LuaJIT-2.0.2.tar.gz |
# cd LuaJIT-2.0.2 |
# make |
出现如下内容表示编译成功 |
OK Successfully built LuaJIT |
make [1]: Leaving directory `/usr/ local /src/LuaJIT-2.0.2/src' |
==== Successfully built LuaJIT 2.0.2 ==== |
# make install |
出现如下内容,表示安装成功 |
==== Successfully installed LuaJIT 2.0.2 to /usr/ local ==== |
# cd /usr/local/src |
# wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.6.tar.gz |
# tar -xzvf v0.8.6 |
3.1 安装
# cd /usr/local/src/ |
# wget http://nginx.org/download/nginx-1.4.2.tar.gz |
# tar -xzvf nginx-1.4.2.tar.gz |
# cd nginx-1.4.2 |
//先导入环境变量,告诉nginx去哪里找luajit |
# export LUAJIT_LIB=/usr/local/lib |
# export LUAJIT_INC=/usr/local/include/luajit-2.0 |
# ./configure --prefix=/usr/local/nginx-1.4.2 --add-module=../lua-nginx-module-0.8.6 |
# make -j2 |
# make install |
# /usr/local/nginx-1.4.2/sbin/nginx -v |
./objs/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file : No such file or directory |
解决方法: |
# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2 |
nginx配置文件加入如下配置:
location ~* ^/2328(/.*) { |
default_type 'text/plain' ; |
content_by_lua 'ngx.say("hello, ttlsa lua")' ; |
} |
5.1 启动nginx
# /usr/local/nginx-1.4.2/sbin/nginx |
view source
print?
# curl http://test.ttlsa.com/2328/ |
hello, ttlsa lua //使用curl测试 |
相关文章推荐
- nginx 301重定向方法
- web架构 之 Nginx负载均衡
- nginx安装
- nginx使用cronolog切割日志安装、部署、应用测试
- tnginx调用lua模块编译安装
- nginx日志方面知识整理
- web架构 之 Nginx负载均衡 负载策略配置
- nginx+keepalived
- nginx配置笔记
- Nginx与PHP(FastCGI)的安装、配置与优化
- Mint+Nginx+Mysql+php
- 实现Nginx通过反代对Java环境和Perl环境的支持
- nginx的中文rewrite规则
- Nginx交互式管理脚本
- 文章3:Nginx源码分析-ngx_list_t单链表
- nginx根据cookie分流
- yum 安装 PHP,apache,nginx,mysql
- Windows下nginx的安装与配置
- Nginx 简单的负载均衡配置示例
- lvs、haproxy、nginx 负载均衡的比较分析