簡體   English   中英

如何在 nginx 容器中使用帶有 lua 的環境變量

[英]How can I use environment variables with lua in nginx container

我想在容器上使用 nginx,並且 nginx 將讀取容器的環境變量。 我搜索並發現使用 lua 模塊使其成為可能,但由於某種原因我無法在 nginx 本身上加載 lua 模塊。 請幫忙,添加 Dockerfile 和 nginx.conf
文件

FROM nginx:1.15-alpine

RUN  mkdir -p /run/nginx && \
     apk add nginx-mod-http-lua

WORKDIR /usr/src/app

COPY build /usr/src/app/build
COPY mime.types /usr/src/app

COPY nginx.conf /usr/src/app

EXPOSE 8080

CMD [ "nginx", "-c", "/usr/src/app/nginx.conf", "-g", "daemon off;" ]

配置文件

load_module /usr/lib/nginx/modules/ndk_http_module.so;
load_module /usr/lib/nginx/modules/ngx_http_lua_module.so;

pcre_jit on;

events {

}

http {
    server {
        listen 8080;
        set_by_lua $db_api 'return os.getenv("DB_API")';
        location /db/ {
            proxy_pass $db_api;
        }

        location / {
            root /usr/src/app/build;
            index index.html;
        }
    }
}

這些是我得到的錯誤:

2020/09/24 17:06:49 [alert] 1#1: detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
2020/09/24 17:06:49 [error] 1#1: lua_load_resty_core failed to load the resty.core module from https://github.com/openresty/lua-resty-core; ensure you are using an OpenResty release from https://openresty.org/en/download.html (rc: 2, reason: module 'resty.core' not found:
        no field package.preload['resty.core']
        no file './resty/core.lua'
        no file '/usr/share/luajit-2.1.0-beta3/resty/core.lua'
        no file '/usr/local/share/lua/5.1/resty/core.lua'
        no file '/usr/local/share/lua/5.1/resty/core/init.lua'
        no file '/usr/share/lua/5.1/resty/core.lua'
        no file '/usr/share/lua/5.1/resty/core/init.lua'
        no file '/usr/share/lua/common/resty/core.lua'
        no file '/usr/share/lua/common/resty/core/init.lua'
        no file './resty/core.so'
        no file '/usr/local/lib/lua/5.1/resty/core.so'
        no file '/usr/lib/lua/5.1/resty/core.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './resty.so'
        no file '/usr/local/lib/lua/5.1/resty.so'
        no file '/usr/lib/lua/5.1/resty.so'
        no file '/usr/local/lib/lua/5.1/loadall.so')
nginx: [error] lua_load_resty_core failed to load the resty.core module from https://github.com/openresty/lua-resty-core; ensure you are using an OpenResty release from https://openresty.org/en/download.html (rc: 2, reason: module 'resty.core' not found:
        no field package.preload['resty.core']
        no file './resty/core.lua'
        no file '/usr/share/luajit-2.1.0-beta3/resty/core.lua'
        no file '/usr/local/share/lua/5.1/resty/core.lua'
        no file '/usr/local/share/lua/5.1/resty/core/init.lua'
        no file '/usr/share/lua/5.1/resty/core.lua'
        no file '/usr/share/lua/5.1/resty/core/init.lua'
        no file '/usr/share/lua/common/resty/core.lua'
        no file '/usr/share/lua/common/resty/core/init.lua'
        no file './resty/core.so'
        no file '/usr/local/lib/lua/5.1/resty/core.so'
        no file '/usr/lib/lua/5.1/resty/core.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './resty.so'
        no file '/usr/local/lib/lua/5.1/resty.so'
        no file '/usr/lib/lua/5.1/resty.so'
        no file '/usr/local/lib/lua/5.1/loadall.so')

這是 docker build 和 run 命令:

docker build -t client:1.0.0 --no-cache .

docker run -p 80:8080 -it -e DB_API=DB_API_URL client:1.0.0

在頂部添加env指令,它可以處理問題的注釋

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM