我在使用nginx devel(ndk)和lua-module时遇到了一些麻烦。 我使用以下configuration编译nginx-rpm:
./configure \ --prefix=%{_sysconfdir}/nginx/ \ --sbin-path=%{_sbindir}/nginx \ --conf-path=%{_sysconfdir}/nginx/nginx.conf \ --error-log-path=%{_localstatedir}/log/nginx/error.log \ --http-log-path=%{_localstatedir}/log/nginx/access.log \ --pid-path=%{_localstatedir}/run/nginx.pid \ --lock-path=%{_localstatedir}/run/nginx.lock \ --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \ --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \ --user=%{nginx_user} \ --group=%{nginx_group} \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-cc-opt="%{optflags} $(pcre-config --cflags)" \ --add-module=%{_builddir}/nginx-%{version}/mods/upload_progress \ --add-module=%{_builddir}/nginx-%{version}/mods/ngx_devel_kit \ --add-module=%{_builddir}/nginx-%{version}/mods/lua-nginx-module \
在安装之后调用nginx -V也显示ngx和lua似乎已经安装/激活了。 但是,当我做到以下几点:
location /abc/ { # For demonstration purposes only... ngx.flush(true); expires 30d; }
我总是得到以下错误:
nginx: [emerg] unknown directive "ngx.flush(true)" in /etc/nginx/conf.d/default.conf:53 nginx: configuration file /etc/nginx/nginx.conf test failed
我的configuration有什么问题? 有什么我需要激活在conf-file中使用ngx指令?
提前感谢您的任何build议!
ngx.flush()是NginxLuaModule的Lua函数之一,而不是nginxconfiguration指令。
为了达到你所期望的行为(只是冲洗内容),做到这一点:
location /abc/ { content_by_lua ' ngx.flush(true); '; expires 30d; }
您必须将Lua代码封装到其中一个*_by_lua指令中,或者使用您的nginxconfiguration中的一个*_by_lua_file指令从文件加载代码。
Lua代码可以在不同的上下文中执行,例如,在重写状态下( rewrite_by_lua )设置variables( set_by_lua ),为内容( content_by_lua )提供服务等等。
你应该看看nginx的wiki页面 。
请注意,执行Lua代码的每个上下文都被devise为执行不同的任务,并在处理和提供请求时在不同的时间运行。
这使得以通用的方式解释代码行为,代码要求或可用函数几乎是不可能的