无法在 rewrite_by_lua_block 中访问 ngx.var
2020-6-2 16:46:30
收藏:0
阅读:124
评论:1
我尝试将值设置为 nginx 变量,但是出现错误:
[error] 47#47: *382 lua entry thread aborted: runtime error: rewrite_by_lua(myconf.conf:23):2: attempt to index field 'var' (a nil value)
stack traceback:
coroutine 0:
rewrite_by_lua(myconf.conf:23): in function <rewrite_by_lua(myconf.conf:23):1>, client: ip, server: *.host, request: "GET / HTTP/1.1", host: "host"
我配置文件的一部分如下:
set $upstream_new '';
rewrite_by_lua_block {
ngx.var.upstream_new = "8.8.8.8";
}
如果有影响,我是在 docker 中运行 nginx。编译的参数如下:
--prefix=/var/www/nginx --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin --modules-path=/usr/lib/nginx/modules --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/tmp/nginx.pid --http-client-body-temp-path=/var/cache/nginx/body --http-fastcgi-temp-path=/var/cache/nginx/fastcgi --http-proxy-temp-path=/var/cache/nginx/proxy --http-scgi-temp-path=/var/cache/nginx/scgi --http-uwsgi-temp-path=/var/cache/nginx/uwsgi --with-pcre --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_degradation_module --with-http_v2_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_slice_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-mail --with-mail_ssl_module --with-threads --with-file-aio --with-compat --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=/usr/src/nginx/ngx_devel_kit-0.3.1 --add-module=/usr/src/nginx/ngx_cache_purge-2.3 --add-dynamic-module=/usr/src/nginx/nginx_upstream_check_module-master --add-dynamic-module=/usr/src/nginx/lua-nginx-module-0.10.16rc5 --add-dynamic-module=/usr/src/nginx/headers-more-nginx-module-0.33 --add-dynamic-module=/usr/src/nginx/ngx_brotli --add-dynamic-module=/usr/src/nginx/ngx_http_auth_pam_module-1.5.1 --add-dynamic-module=/usr/src/nginx/echo-nginx-module-0.62rc1 --add-dynamic-module=/usr/src/nginx/ngx-fancyindex-0.4.4 --add-dynamic-module=/usr/src/nginx/nginx-dav-ext-module-3.0.0 --add-dynamic-module=/usr/src/nginx/ngx_http_substitutions_filter_module-0.6.4 --add-dynamic-module=/usr/src/nginx/nginx-upload-progress-module-0.9.2 --add-dynamic-module=/usr/src/nginx/nchan-1.2.7
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

nginx -V检查所有编译标志,并查看是否存在所有 Lua 模块。我在 OpenResty 上尝试以下代码块工作正常。
set $upstream_new ''; rewrite_by_lua_block { ngx.var.upstream_new = "8.8.8.8"; }和
set $upstream_new ''; access_by_lua ' ngx.var.upstream_new = "8.8.8.8"; ';如果你是新手,agentzh 的 Nginx 教程 可能有帮助。