搭建OpenResty(Nginx+Lua)
这篇文章是一个多月前写的,当时之所以搭建这个是为了最大程度上发挥Nginx的高并发效率(主要是结合lua脚本),参考的话,主要参考张开涛先生写的跟开涛学Nginx+lua系列文章,地址为:https://jinnianshilongnian.iteye.com/blog/2190344
当时本人按照张开涛写的一步一步搭建,当然了也发现一些小问题,所以在此将其发表出去,另外强调一点,开发人员无论是平时编写代码或者是调研新技术或者实践,最好也写写文档总结一下。
我写文档的主要目的,一来让自己思路更加清晰,二来为博文积累素材,三来这是一个秘密。
下面进入正题吧
1.创建目录/usr/servers
mkdir -p /usr/servers
cd /usr/servers/
2.安装依赖(不同的系统环境需要以不同的方式安装依赖,具体可以参考该地址: //openresty.org/#Installation)
apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl
3.下载ngx_openresty-1.7.7.2.tar.gz并解压
wget http://openresty.org/download/ngx_openresty-1.7.7.2.tar.gz
tar -xzvf ngx_openresty-1.7.7.2.tar.gz
ngx_openresty-1.7.7.2/bundle目录里存放着nginx核心和很多第三方模块,比如有我们需要的Lua和LuaJIT
4.安装LuaJIT
cd bundle/LuaJIT-2.1-20150120/
make clean && make && make install
ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
5.下载ngx_cache_purge模块,该模块用于清理nginx缓存
cd /usr/servers/ngx_openresty-1.7.7.2/bundle
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar -xvf 2.3.tar.gz
6.下载nginx_upstream_check_module模块,该模块用于ustream健康检查
cd /usr/servers/ngx_openresty-1.7.7.2/bundle
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar -xvf v0.3.0.tar.gz
7.安装ngx_openresty
cd /usr/servers/ngx_openresty-1.7.7.2
./configure --prefix=/usr/servers --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
make && make install
--with*** 安装一些内置/集成的模块
--with-http_realip_module 取用户真实ip模块
-with-pcre Perl兼容的达式模块
--with-luajit 集成luajit模块
--add-module 添加自定义的第三方模块,如此次的ngx_che_purge
8.启动nginx
/usr/servers/nginx/sbin/nginx
9.配置nginx+lua开发环境
(1) 编辑nginx.conf配置文件
vim /usr/servers/nginx/conf/nginx.conf
(2)在http部分添加如下配置
#lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找
lua_package_path "/usr/servers/lualib/?.lua;;"; #lua 模块
lua_package_cpath "/usr/servers/lualib/?.so;;"; #c模块
其实之所以编写example.conf,是考虑Nginx+Lua开发文件会越来越多,如果全部挤在nginx文件下的话,不利于管理和维护。
/usr/example/example.conf配置文件如下 :
server {
listen 80;
server_name _; location /lua {
default_type 'text/html';
lua_code_cache off;
content_by_lua_file /usr/example/lua/test.lua;
}
}
test.lua内容如下:
ngx.say("hello world");
重启Nginx在浏览器输入:http://IP/lua,出现hello world表示成功
例如:
最后完整的nginx.conf文件如下:
#user nobody;
worker_processes 2; error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http { include mime.types;
default_type application/octet-stream;
#lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找
lua_package_path "/usr/servers/lualib/?.lua;;"; #lua 模块
lua_package_cpath "/usr/servers/lualib/?.so;;"; #c模块
include /usr/example/example.conf;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
搭建OpenResty(Nginx+Lua)的更多相关文章
- (转)OpenResty(nginx+lua) 开发入门
原文:https://blog.csdn.net/enweitech/article/details/78519398 OpenResty 官网:http://openresty.org/ Open ...
- CentOS安装OpenResty(Nginx+Lua)开发环境
一.简介 OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩展性极高 ...
- OpenResty(nginx+lua) 入门
OpenResty 官网:http://openresty.org/ OpenResty 是一个nginx和它的各种三方模块的一个打包而成的软件平台.最重要的一点是它将lua/luajit打包了进来, ...
- 【原创】大叔问题定位分享(36)openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil
openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil This function returns nil if the request ...
- OpenResty(Nginx+Lua)开发入门
Nginx入门 本文目的是学习Nginx+Lua开发,对于Nginx基本知识可以参考如下文章: nginx启动.关闭.重启 http://www.cnblogs.com/derekchen/archi ...
- 跟我学OpenResty(Nginx+Lua)开发目录贴 (转)
使用Nginx+Lua开发近一年的时间,学习和实践了一些Nginx+Lua开发的架构,为了让更多人使用Nginx+Lua架构开发,利用春节期间总结了一份基本的学习教程,希望对大家有用.也欢迎谈探讨学习 ...
- 【原创】运维基础之OpenResty(Nginx+Lua)+Kafka
使用docker部署 1 下载 # wget https://github.com/doujiang24/lua-resty-kafka/archive/v0.06.tar.gz# tar xvf v ...
- OpenResty(Nginx)+Lua+GraphicsMagick实现缩略图功能
http://www.hopesoft.org/blog/?p=1188 http://www.imagemagick.org/download/ 2.用法 原始图片是input.jpg,尺寸:160 ...
- OpenResty部署nginx及nginx+lua
因为用nginx+lua去开发,所以会选择用最流行的开源方案,就是用OpenResty nginx+lua打包在一起,而且提供了包括redis客户端,mysql客户端,http客户端在内的大量的组件 ...
随机推荐
- c#英文大小写快捷键
选中一段英文 Ctrl+U 转小写 Ctrl+Shift+U 转大写
- Modbus通信协议 【 初识 Modbus】
Modbus协议 Modbus 协议是应用于电子控制器上的一种通用语言.通过此协议,控制器相互之间.控制器经由网络(例如以太网)和其它设备之间可以通信.它已经成为一通用工业标准.有了它,不同厂 ...
- Integer to Boolean strange syntax
Question: I'm less than a year into C++ development (focused on other languages prior to this) and I ...
- Ansible安装 入门教程
learn一门新技术咯: ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置 ...
- c语言学习笔记-do......while
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一.do......while函数意义 循环执行(人机交互) 二.do......while函数结构 do{ 语句1: 语句2: ...
- codechef QCHEF(不删除莫队)
题意 题目链接 给出长度为\(n\)的序列,每次询问区间\([l, r]\),要求最大化 \(max |x − y| : L_i ≤ x, y ≤ R_i and A_x = A_y\) Sol 标算 ...
- 【代码笔记】Web-ionic-toggle(切换开关)
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- sql语句进阶教程
转载自:http://blog.csdn.net/u011001084/article/details/51318434 最近从图书馆借了本介绍SQL的书,打算复习一下基本语法,记录一下笔记,整理一下 ...
- Linux中用find命令查找当前文件夹下的.elf文件
find ./ -name "*.elf" 注意:""不能少
- 【PAT】B1064 朋友数(20 分)
以前写的,逻辑不好,过后再改 #include<stdio.h> #include<algorithm> #include<math.h> using namesp ...