Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with lua #144

Open
AlexFisher94 opened this issue Aug 21, 2024 · 1 comment
Open

Error with lua #144

AlexFisher94 opened this issue Aug 21, 2024 · 1 comment

Comments

@AlexFisher94
Copy link

Describe the bug
Got an error from lua

2024/08/19 14:58:25 [error] 36#36: *771 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:24):2: module 'cjson' not found:
        no field package.preload['cjson']
        no file './cjson.lua'
        no file '/usr/local/share/luajit-2.1/cjson.lua'
        no file '/usr/local/share/lua/5.1/cjson.lua'
        no file '/usr/local/share/lua/5.1/cjson/init.lua'
        no file './cjson.so'
        no file '/usr/local/lib/lua/5.1/cjson.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
coroutine 0:
        [C]: in function 'require'
        content_by_lua(nginx.conf:24):2: in main chunk, client: 10.33.45.224, server: , request: "GET /lua HTTP/2.0", host: "sa-vm-sentry-test.sam.loc:5151"

To Reproduce

  1. docker pull fabiocicerchia/nginx-lua
  2. Correcting docker-compose.yml and docker-compose up -d
  3. docker logs container id
  4. See error

Expected behavior
See JSON logs from Sentry

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Hello!
I want to check my JSON files from Sentry.
I've set up sentry and use this Docker-image nginx-lua
And when i want to see json from sentry in logs - i've got an error (described above)

What i do wrong?

Here's my nginx.conf

worker_processes auto;

events {
    worker_connections 1024;
}

http {
    lua_shared_dict request_body 30m;

    # Настройка путей для логов
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    ssl_certificate /etc/ssl/svrauto/public.crt;
    ssl_certificate_key /etc/ssl/svrauto/private.key;

    server {
        listen 443 ssl http2;
        client_body_buffer_size 20K;
        client_header_buffer_size 4k;
        client_max_body_size 12m;
        large_client_header_buffers 2 12k;
        location /lua {
    # Обрабатываем POST запросы
            content_by_lua_block {
                local cjson = require "cjson"
                local log = ngx.log
                local ERR = ngx.ERR

                ngx.req.read_body()
                local body = ngx.req.get_body_data()

                if body then
                    local success, json = pcall(cjson.decode, body)

                    if success then
                        -- Записываем в лог содержимое JSON
                        log(ERR, "Received JSON: ", cjson.encode(json))

                        -- Отправляем JSON как строку
                        ngx.say(cjson.encode(json))
                    else
                        -- Записываем ошибку в лог
                        log(ERR, "Invalid JSON: ", body)

                        ngx.status = ngx.HTTP_BAD_REQUEST
                        ngx.say("Invalid JSON")
                    end
                else
                    -- Записываем ошибку в лог
                    log(ERR, "Empty body received")

                    ngx.status = ngx.HTTP_BAD_REQUEST
                    ngx.say("Empty body")
                end
            }
        }
    }
}

Thanks for any help!

@fabiocicerchia
Copy link
Owner

Hi @AlexFisher94, cjson is not install by default, you can enable it by running the following commands:

apk add gcc musl-dev coreutils wget
luarocks install lua-cjson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants