openresty 配置模块化
openresty 配置模块化
模块搜索路径
lua_package_path:lua模块搜索路径
语法格式:lua_package_path <lua-style-path-str>
环境:httpSets the Lua module search path used by scripts specified
by set_by_lua, content_by_lua and others.
* 设置set_by_lua、content_by_lua等指令中的模块搜索路径The path string is in standard Lua path form, and ;; can
be used to stand for the original search paths
* 设置的path是标准的lua格式
* ;; ==> 表示原始搜索路径# 示例
lua_package_path "/usr/local/openresty/modules/?.lua;;" #绝对路径
lua_package_path "modules/?.lua;;" #相对路径
lua_package_path "${prefix}/modules/?.lua;;" #${prefix}表示编译时的--prefix参数
lua_package_cpath:c模块搜索路径
语法格式:lua_package_cpath <lua-style-cpath-str>
环境:httpSets the Lua C-module search path used by scripts
specified by set_by_lua, content_by_lua and others.
* 设置set_by_lua、content_by_lua等指令中使用的c模块搜索路径The cpath string is in standard Lua cpath form, and
;; can be used to stand for the original cpath
* cpath string是标准的lua cpath格式
* ;; ==> 表示原始搜索路径
配置模块
redis_config.lua
local config = {}
config.host = "172.18.0.81";
config.port = 6379return config
nginx.conf
#user nobody;
#worker_processes 1;pcre_jit on;#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;#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;proxy_temp_path /var/run/openresty/nginx-proxy;fastcgi_temp_path /var/run/openresty/nginx-fastcgi;uwsgi_temp_path /var/run/openresty/nginx-uwsgi;scgi_temp_path /var/run/openresty/nginx-scgi;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;include /etc/nginx/conf.d/*.conf;# 添加自定义的模块搜索路径lua_package_path "/usr/local/openresty/config/?.lua;;";
}
default.conf
server {listen 80;server_name localhost;location / {root /usr/local/openresty/nginx/html;index index.html index.htm;}local /test {content_by_lua_block {local redis = require "resty.redis";local config = require "redis.config";local red = redis:new();red:set_timeouts(1000, 1000, 1000);local ok, err = red:connect(config.host, config.port);if not ok thenngx.say("red failed to connect: ", err)returnendngx.say("red:set('1','gtlx')");local res, err = red:set('1','gtlx');if not res thenngx.say("failed to set: ", err)returnendngx.say("\nred:get('1')");res, err = red:get('1');if not res thenngx.say("failed to get: ", err)returnendngx.say("get读取结果 ==> ", res);}}error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/local/openresty/nginx/html;}}
创建容器
#redis
docker run -it -d --net fixed --ip 172.18.0.81 -p 6301:6379 --name redis redis#openresty
docker run -it -d --net fixed --ip 172.18.0.82 -p 6004:80 \
-v /Users/huli/lua/openresty/config/redis_config.lua:/usr/local/openresty/config/redis_config.lua \
-v /Users/huli/lua/openresty/config/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf \
-v /Users/huli/lua/openresty/config/default2.conf:/etc/nginx/conf.d/default.conf \
--name open-config lihu12344/openresty
使用测试
huli@bogon config % curl localhost:6004/test
red:set('1','gtlx')red:get('1')
get读取结果 ==> gtlx
openresty 配置模块化相关推荐
- openresty配置部署
环境:centos yum install -y readline-devel pcre-devel openssl-devel gcc yum install -y g++ make automak ...
- nginx和openresty配置静态资源时,样式错乱
问题 nginx和openresty配置静态资源时,样式错乱,页面没有报错,查看css,作为静态文件已经加载了,但是不起作用. 原因 CSS加载过程,发现CSS加载时Content Type为&quo ...
- openresty的html文件夹在,Openresty 配置访问静态文件,拆分路径
http { server { listen 8080; location / { # default_type text/html; # content_by_lua ' # ngx.say(&qu ...
- OpenResty+Keepalived组建高可用集群+双主模式
* 环境: system version:CentOS Linux release 7.5.1804 (Core) 3.10.0-862.9.1.el7.x86_64 nginx version:op ...
- Apache 2.2 虚拟主机配置(本人推荐的)
1.域名问题 假设我们有两个域名:www.aaa.com和www.bbb.com 为了方便测试,我们可以通过系统下的hosts文件,设定解析这两个域名时对应的ip,在xp系统盘的 windows\sy ...
- OpenResty请求参数处理
获取参数的API OpenResty中提供了一些API用来获取不同类型的前端请求参数: 获取参数并返回 在前端发起的ajax请求如图: 可以看到商品id是以路径占位符方式传递的,因此可以利用正则表达式 ...
- vimpython配色_超漂亮 vim 配置:space-vim
space-vim 现已支持 Layer ,以下内容大都陈旧,欢迎访问 github 查看最新版本: >>>> space-vim 关于 vim 的更多文章欢迎关注专栏: sp ...
- openresty nginx php,diy 你的nginx-OpenResty
OpenResty OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩 ...
- 程序常用配置文件格式介绍
文章目录 1.键值对 2.JSON 2.1 JSON 语法 2.2 JSON 实例 2.3 JSON 解析 3.XML 3.1 XML 语法 3.2 XML 实例 3.3 XML 解析 4.YAML ...
最新文章
- python画折线图详解-Python数据可视化(一) 绘制折线图和散点图
- natcat for mysql_用Navicat for mysql连接mysql报错1251-解决办法
- P1852-跳跳棋【思维,差分,二分】
- 基于.net core 3 和 Orleans 3 的 开发框架:Phenix Framework 7
- 使用强大的 Mockito 来测试你的代码
- JAVA程序员从菜鸟到菜鸟
- ORACLE--Connect By、Level、Start With的使用(Hierarchical query-层次查询)
- 别人问了个问题:有没有选择JAVA开发的设计文档
- 【收山之作】我手上所有GALGAME 游戏资源封装工具下载
- 世嘉土星和世嘉MD手柄定义,如何自制土星和MD手柄
- Flink-CDC 动态监控 mysql 数据表
- 如何利用少数粉丝,实现短时间流量倍增?
- Senparc.Weixin.MP SDK 微信公众平台开发教程(十六):AccessToken自动管理机制
- python 条形图填充疏密_python matplotlib模块: fill_between(填充曲线)
- 为Gridea主题添加思源宋体字体支持
- SpringMVC —— @ResponseBody原理
- openEuler上一键部署opengauss数据库
- 山外KL26的J-link连接与程序下载
- MySQL索引的正确使用姿势
- 项目进展:淘宝店铺抓取
热门文章
- arcgis的计算统计工具(caculate statistics)在哪?
- 【一帘幽梦】英语之路——10
- 菜鸟程序员与资深程序员的区别
- 百度地图 驾车/公交查询Demo(支持多起点多终点)
- “超级血狼月”震撼登场!快看史诗级的三合一天文奇观
- python历史净值分析_Python 爬取基金历史净值数据
- 分享:详记一次MySQL千万级大表优化过程!
- 这才是小程序真正价值 但他绝不会取代App
- java取开始时间和结束时间_java获取指定开始时间与结束时间之间的所有日期
- java jmap instances_jmap命令详解