openresty:init_by_lua指令的问题(这里不允许获取"指令")

时间:2014-04-08 17:39:40

标签: nginx openresty

我尝试使用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 conf文件是:

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和服务器块中,我得到了同样的错误init_by_lua

2 个答案:

答案 0 :(得分:1)

您是否尝试将其放入http {...}块?

  http {
      init_by_lua 'local zaz = 4321';
      server { ... }
    }

答案 1 :(得分:1)

init_by_lua仅允许http内容:http://wiki.nginx.org/HttpLuaModule#init_by_lua

http {
    init_by_lua '
        require "resty.core"
    ';
}