Nginx使用lua指令报错

发布于 2022-09-08 00:03:21 字数 2482 浏览 18 评论 0

nginx配置文件如下:

server {
    listen 8091;
    server_name localhost;
    access_log /var/log/nginx/log/test.access.log main;

    location /hello {
    default_type 'text/plain';
    content_by_lua 'ngx.say("hello, lua")';
    }

    location /myip {
    default_type 'text/plain';
    content_by_lua '
        clientIP = ngx.req.get_headers()["x_forwarded_for"]
        ngx.say("IP:",clientIP)
    ';
    }

    location / {
    default_type "text/html";
    content_by_lua_file /opt/app/lua/test.lua;
    }
    ....

使用nginx -s reload没有报错,当在浏览器访问ip:9091时,error.log打印出来错误:

2018/10/13 14:54:51 [emerg] 19933#19933: unknown directive "content_by_lua" in /etc/nginx/conf.d/test.conf:8

提示指令错误:我已经安装过了相关的模块
nginx -V查看:

nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/run/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi-temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi-temp --http-scgi-temp-path=/var/cache/nginx/scgi-temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/opt/download/ngx_devel_kit --add-module=/opt/download/lua-nginx-module-0.10.13

请问如何解决?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧瑾黎汐 2022-09-15 00:03:21
建议直接用章义春老师弄得openresty,否则你就要自己编译增加扩展
血之狂魔 2022-09-15 00:03:21

我也碰到同样的情况,nginx -V看着nginx-lua模块都已经编译安装完成了,但是一直报*_by_lua(_file)的指令找不到,请问您是如何解决的

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文