openresty :init_by_lua 指令存在问题(出现“此处不允许该指令”错误)

我试图使用init_by_lua指令:https://github.com/chaoslawful/lua-nginx-module#init_by_lua

但nginx无法启动,日志中显示的消息如下:

2014/04/08 17:33:53 [emerg] 2105#0: "init_by_lua" directive is not allowed here in /genap/genap-nginx.conf:6

nginx配置文件如下:

worker_processes  1;

error_log logs/error.log;

init_by_lua 'local zaz = 4321';

events {
    worker_connections 1024;
}

http {
    server {

        lua_code_cache off;
        listen 80;
        location / {
            default_type text/html;
            content_by_lua_file /vagrant/genap_host_proxy/content.lua;

        }
    }
}

我已经尝试把init_by_lua放在http和server块中,但我得到相同的错误init_by_lua。

点赞
用户2259450
用户2259450

你尝试将它放入 http {...} 块中了吗?

  http {
      init_by_lua 'local zaz = 4321';
      server { ... }
    }
2014-12-01 13:37:51
用户380774
用户380774

init_by_lua 只允许在 http 内容中使用: http://wiki.nginx.org/HttpLuaModule#init_by_lua

http {
    init_by_lua '
        require "resty.core"
    ';
}
2015-04-02 09:55:31