openresty / stream-lua-nginx-module

Embed the power of Lua into NGINX TCP/UDP servers
BSD 2-Clause "Simplified" License
725 stars 199 forks source link

nginx "content_by_lua_block" directive is not allowed here #333

Open nejinn opened 9 months ago

nejinn commented 9 months ago

nginx: [emerg] "content_by_lua_block" directive is not allowed here

stream {
    # define a TCP server listening on the port 1234:
    server {
        listen 1234;
        content_by_lua_block {
            ngx.say("Hello, Lua!")
        }
    }
}

nginx -v nginx version: nginx/1.22.0

nginx -V --prefix=/usr/local/nginx --with-pcre=../pcre-8.45 --with-zlib=../zlib-1.3 --with-openssl=../openssl-1.1.1q --pid-path=/data/logs/nginx/nginx.pid --error-log-path=/data/logs/nginx/error.log --http-log-path=/data/logs/nginx/access.log --lock-path=/var/run/nginx.lock --modules-path=/usr/local/nginx/modules --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 --with-threads --with-http_sub_module --with-http_v2_module --with-http_auth_request_module --with-http_realip_module --with-http_secure_link_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_ssl_module --with-http_slice_module --with-http_stub_status_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail --with-mail_ssl_module --with-http_addition_module --with-http_random_index_module --with-compat --with-stream --with-file-aio --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib,--as-needed,-O1,--sort-common --add-module=/usr/local/src/ngx_devel_kit-0.3.1 --add-module=/usr/local/src/lua-nginx-module-0.10.21 --add-dynamic-module=/usr/local/src/echo-nginx-module-0.62 --add-dynamic-module=/usr/local/src/stream-lua-nginx-module-0.0.14rc1

when in http is ok

        location /lua {
            default_type 'text/plain';

            content_by_lua 'ngx.say("hello, lua")';
        }
zhuizhuhaomeng commented 9 months ago

--add-dynamic-module=/usr/local/src/stream-lua-nginx-module-0.0.14rc1

have you loaded the stream-lua-nginx-module?

nejinn commented 9 months ago

--add-dynamic-module=/usr/local/src/stream-lua-nginx-module-0.0.14rc1

have you loaded the stream-lua-nginx-module?

yes, stream-lua-nginx-module was in my nignx modules folder /usr/local/nginx/modules/

zhuizhuhaomeng commented 9 months ago

you need to load the module via load_module https://nginx.org/en/docs/ngx_core_module.html#load_module