openresty ngx_lua获取环境变量
openresty ngx_lua获取环境变量
环境变量
ngx.config.subsystem:当前请求的nginx环境
语法格式:subsystem = ngx.config.subsystem
* 如果在http模块下,返回字符串http
* 如果在stream模块下,返回字符串stream环境:init_by_lua*、init_worker_by_lua*、log_by_lua*、ngx.timer.*、set_by_lua*、rewrite_by_lua*、content_by_lua*、access_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.config.debug:是否是调试模式
语法格式:debug = ngx.config.debug
* 判断请求是否在调试模式下执行
* 如果需要在调试模式下执行某些操作,可以用该语句进行判断环境:init_by_lua*、init_worker_by_lua*、log_by_lua*、ngx.timer.*、set_by_lua*、rewrite_by_lua*、content_by_lua*、access_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.config.nginx_version:获取nginx的版本号
语法格式:version = ngx.config.nginx_version
* 获取nginx的版本号环境:init_by_lua*、init_worker_by_lua*、log_by_lua*、ngx.timer.*、set_by_lua*、rewrite_by_lua*、content_by_lua*、access_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.config.ngx_lua_version:获取ngx_lua的版本号
语法格式:version = ngx.config.ngx_lua_version
* 获取ngx_lua的版本号环境:init_by_lua*、log_by_lua*、ngx.timer.*、access_by_lua*、set_by_lua*、rewrite_by_lua*、content_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.config.prefix:获取编译nginx时指定的prefix参数
语法格式:prefix = ngx.config.prefix()
* 获取编译nginx指定的参数--prefix
* 如果nginx启动时使用了-p,则输出-p环境:init_by_lua*、init_worker_by_lua*、log_by_lua*、ngx.timer.*、set_by_lua*、rewrite_by_lua*、content_by_lua*、access_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.config.nginx_configure:获取编译nginx时,configure设置的参数
语法格式:configure = ngx.config.nginx_configure()
* 获取编译nginx时,configure指定的参数环境:init_by_lua*、log_by_lua*、ngx.timer.*、access_by_lua*、set_by_lua*、rewrite_by_lua*、content_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.worker.id:获取worker进程的id
语法格式:id = ngx.worker.id()
* 获取worker进程的id环境:init_by_lua*、log_by_lua*、ngx.timer.*、access_by_lua*、set_by_lua*、rewrite_by_lua*、content_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.worker.count:获取worker进程的数量
语法格式:count = ngx.worker.count()
* 获取worker进程的数量,nginx配置文件中worker_processes的数量环境:init_by_lua*、init_worker_by_lua*、log_by_lua*、ngx.timer.*、set_by_lua*、rewrite_by_lua*、content_by_lua*、access_by_lua*、header_filter_by_lua*、body_filter_by_lua*
ngx.worker.exiting:判断worker进程是否退出
语法格式:exiting = ngx.worker.exiting()
* 判断worker进程是否退出环境:init_by_lua*、init_worker_by_lua*、log_by_lua*、ngx.timer.*、set_by_lua*、rewrite_by_lua*、content_by_lua*、access_by_lua*、header_filter_by_lua*、body_filter_by_lua*
使用示例
default.conf
server {listen 80;server_name localhost;location /test {content_by_lua_block {ngx.say("当前请求的nginx环境 ==> ",ngx.config.subsystem);ngx.say("是否是调试模式 ==> ",ngx.config.debug);ngx.say("nginx版本号 ==> ",ngx.config.nginx_version);ngx.say("ngx_lua版本号 ==> ",ngx.config.ngx_lua_version);ngx.say("nginx prefix ==> ",ngx.config.prefix());ngx.say("nginx configure ==> ",ngx.config.nginx_configure());ngx.say("nginx worker进程id ==> ",ngx.worker.id());ngx.say("nginx worker_processes ==> ",ngx.worker.count());ngx.say("nginx worker进程是否退出 ==> ",ngx.worker.exiting());}}#error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/local/openresty/nginx/html;}}
创建容器
docker run -it -d -p 2003:80 \
-v /Users/huli/lua/openresty/conf8/default.conf:/etc/nginx/conf.d/default.conf \
--name open6 lihu12344/openresty
使用测试
huli@hudeMacBook-Pro conf8 % curl localhost:2003/test
当前请求的nginx环境 ==> http
是否是调试模式 ==> false
nginx版本号 ==> 1021004
ngx_lua版本号 ==> 10021
nginx prefix ==> /usr/local/openresty/nginx/
nginx configure ==> --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../ngx_stream_lua-0.0.11 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' --with-cc='ccache gcc -fdiagnostics-color=always' --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-http_ssl_module
nginx worker进程id ==> 0
nginx worker_processes ==> 1
nginx worker进程是否退出 ==> false
openresty ngx_lua获取环境变量相关推荐
- 【linux】查看环境变量|getenv setenv设置获取环境变量
目录 环境变量类型 查看环境变量 系统的环境变量 进程的环境变量 初始化时载入的环境变量 执行过程中设置的环境变量 环境变量原理 通过函数存取环境变量 getenv & setenv 获取&a ...
- Linux——孤儿进程|进程的优先级 用top命令去修改优先级 其他概念 环境变量 PATH 获取环境变量
目录 孤儿进程 进程的优先级 用top命令去修改优先级 其他概念 环境变量 PATH 获取环境变量 习题 孤儿进程 父进程如果提前退出,那么子进程后退出,进入Z之后,那该如何处理呢? 父进程先退出,子 ...
- php getenv shell,关于php的getenv()方法获取环境变量的问题
php文件的执行 我们比较常用的执行php文件方式有两种 一种是通过浏览器访问服务器(比如apache),然后由服务器来运行相应的php文件 另一种就是通过shell直接运行php命令或者在shell ...
- python os.environ windows_Python基于os.environ从windows获取环境变量
安装python之后,我们往往面临这样一个问题,在命令行输入"python",竟然出错,难道是没有安装成功吗?非也,其实是你的系统环境变量没有设置好.今天,小编就来带大家学学pyt ...
- Go 学习笔记(44)— Go 标准库之 os(获取文件状态、获取/修改文件权限、创建、删除目录和文件、获取进程ID、设置获取环境变量)
1. 概述 os 包提供了操作系统函数的不依赖平台的接口.失败的调用会返回错误值而非错误码.通常错误值里包含更多信息.例如,如果某个使用一个文件名的调用(如Open.Stat)失败了,打印错误时会包含 ...
- win7 docker java开发环境变量_java – Docker. Spring应用程序.设置和获取环境变量
我正试图将我的Spring应用程序停靠. 问题: 我无法从我的Spring应用程序中获取docker容器中的环境变量. Spring配置(2个选项,单独试用) 也试过java URI dbUrl = ...
- java获取环境变量路径_通过System获取java环境变量的路径
通过System获取java环境变量的路径代码为: import java.io.FileNotFoundException; import java.io.FileOutputStream; imp ...
- Qt笔记-profile中基本配置(获取环境变量、设置生成路径、包含文件)
配置好环境变量后通过在profile文件中通过$$(xxx)进行获取. 通过DESTDIR配置生成目标文件的路径. 使用INCLUDEPATH包含文件.如下: QT += guiINCLUDEPATH ...
- (转载)Hadoop map reduce 过程获取环境变量
来源:http://www.linuxidc.com/Linux/2012-07/66337.htm 作者: lmc_wy Hadoop任务执行过程中,在每一个map节点或者reduce节点能获取 ...
最新文章
- android广播过滤器.*,android – BroadcastReceiver与多个过滤器或多个BroadcastReceivers?...
- 工作随笔之nginx 应用场景
- spring gateway 限流持久化_Spring Cloud Gateway 扩展支持动态限流
- Django自带的加密算法及加密模块
- 034_jQuery Ajax的getJSON和getScript方法
- List list=new ArrayList()怎么回事
- GIS实战应用案例100篇(二十一)-全国分省、市、县净初级生产力NPP数据制作实战(附代码)
- 蝗虫算法java代码_蝗虫搜索算法 蝗虫算法:蝗虫优化算法是模拟自然界蝗虫种群捕食行为而提出的一 联合开发网 - pudn.com...
- 那些年关于JavaWeb的点点滴滴,你想看的这里全都有噢~
- 前端素材库网站集合——网站集合
- 『Hammerspoon』Mac 锁屏自动开关蓝牙
- django-haystack 对 多对多字段( ManyToManyField )进行索引
- vpu测试_单独编译IMX6Q的VPU示例程序:mxc_vpu_test.out
- 快手信息流投放平台:快手电商宣告成年
- 什么是ASCII码?
- 股价翻番 人生赢家,python爬取基金 筛选股票
- 一键更新目录下所有git repo的脚本
- 艾司博讯:拼多多商品怎样多件一起付款?
- 神经网络与BP算法(代码实现)
- ENC28J60学习
热门文章
- Sheryl Crow Does the HSN Hustle With New Clothing Line
- 【Zynq UltraScale+ MPSoC解密学习7】Zynq UltraScale+的PMU
- WP模板常用调用函数
- C语言Qt视图实现彩虹渐变效果,我就问你6不6?
- 七彩虹 iGame G-ONE Plus 27寸游戏一体机 评测
- 联想win10进bios的正确方式,并不是按键!!!!!
- 四年级计算机考试反思,小学四年级信息技术考试质量分析报告
- vi/vim的一些干货命令及快捷键(跳转最后一行,跳转行末等)~舒服!!!
- linux网络音频播放,通过 PulseAudio 实现局域网音乐播放
- Xmind 免费安装使用教程