2

I'm trying to use the init_by_lua directive : https://github.com/chaoslawful/lua-nginx-module#init_by_lua

and nginx fails to start, with this message in the log :

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

the nginx conf file is :

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;

        }
    }
}

I've tries putting init_by_lua in the http and server block, and I get the same error init_by_lua

Max L.
  • 9,774
  • 15
  • 56
  • 86

2 Answers2

2

init_by_lua is only allowed in http content: http://wiki.nginx.org/HttpLuaModule#init_by_lua

http {
    init_by_lua '
        require "resty.core"
    ';
}
fannheyward
  • 18,599
  • 12
  • 71
  • 109
1

Have you tried to put it inside the http { ... } block?

  http {
      init_by_lua 'local zaz = 4321';
      server { ... }
    }
Carmine Giangregorio
  • 943
  • 2
  • 14
  • 35