fabiocicerchia / nginx-lua

Latest Nginx with LUA support based on AlmaLinux, Alpine Linux, Amazon Linux, Debian, Fedora, and Ubuntu.
https://hub.docker.com/r/fabiocicerchia/nginx-lua
Other
191 stars 42 forks source link

I am unable to use iconv based on your Docker #142

Closed SnowWindDancing closed 8 months ago

SnowWindDancing commented 8 months ago

this is my dockerfile

#from fabiocicerchia/nginx-lua:1.25.3-fedora39
run apt-get -qq update && apt-get -qq install luarocks make libiconv-hook-dev

run luarocks install lua-cjson
run luarocks install lua-iconv

run wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
run tar -xzvf libiconv-1.13.1.tar.gz
run cd libiconv-1.13.1 && ./configure --prefix=/usr/local
run  cd libiconv-1.13.1 && make -j8 && make install
run ln -s /usr/local/lib/libiconv.so /usr/lib
run ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2

this is code

location /test/ {
            access_by_lua_block {
                local iconv = require("iconv")
                ngx.req.read_body()
                local request_body = ngx.req.get_body_data()

                local decoded_body, err = iconv:convert("gbk", "utf-8", request_body)
                if err then
                    ngx.log(ngx.ERR, "Failed to convert request body from GBK to UTF-8: ", err)
                else
                    ngx.req.set_body_data(decoded_body)
                end

                local iconv = require("iconv")
                ngx.var.resp_body = ngx.arg[1]

                local encoded_body, err = iconv:convert("utf-8", "gbk", ngx.var.resp_body)
                if err then
                    ngx.log(ngx.ERR, "Failed to convert response body from UTF-8 to GBK: ", err)
                else
                    ngx.arg[1] = encoded_body
                end

            }
            proxy_pass http://192.168.2.5:8080/;
    }

this is question lua entry thread aborted: runtime error: access_by_lua(nginx.conf:77):10: attempt to call method 'convert' (a nil value) stack traceback:

SnowWindDancing commented 8 months ago

sorry the dockerfile

from fabiocicerchia/nginx-lua:1.25.3-ubuntu22.04

from fabiocicerchia/nginx-lua:1.25.3-fedora39

run apt-get -qq update && apt-get -qq install luarocks make libiconv-hook-dev

RUN luarocks install lua-cjson run luarocks install lua-iconv run wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz run tar -xzvf libiconv-1.13.1.tar.gz run cd libiconv-1.13.1 && ./configure --prefix=/usr/local run cd libiconv-1.13.1 && make -j8 && make install run ln -s /usr/local/lib/libiconv.so /usr/lib run ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2

SnowWindDancing commented 8 months ago

Lua syntax error