简体   繁体   English

如何在 nginx 容器中使用带有 lua 的环境变量

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

I want to use nginx on a container and that the nginx will read the environment variables of the container.我想在容器上使用 nginx,并且 nginx 将读取容器的环境变量。 I've searched and found that using lua modules makes it possible but for some reason I can't load the lua modules on the nginx itself.我搜索并发现使用 lua 模块使其成为可能,但由于某种原因我无法在 nginx 本身上加载 lua 模块。 Please help, adding Dockerfile and nginx.conf请帮忙,添加 Dockerfile 和 nginx.conf
Dockerfile文件

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;" ]

nginx.conf配置文件

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;
        }
    }
}

and these are the errors I get:这些是我得到的错误:

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')

and this is the docker build and run commands:这是 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.

相关问题 如何使用 env 文件将环境变量传递到独立的 vscode 远程容器中? - How can I use an env file to pass environment variables into a standalone vscode remote container? nginx:使用环境变量 - nginx: use environment variables 如何将Jenkins环境变量传递给Docker容器? - How can I pass Jenkins environment variables to docker container? 如何将环境变量传递给Terraform的Docker容器? - How can I pass environment variables to a Docker container with Terraform? 如何使用 Powershell 在 Windows 容器中使用环境变量 - How to use environment variables in Windows container with Powershell 如何在 docker compose 上为 nginx 容器设置环境变量? - How to set environment variables on docker compose for nginx container? 如何将环境变量用作docker容器的名称? - How can I use an environment variable as a name for a docker container? 如何在docker run命令中使用环境变量? - How can I use environment variables in a docker run command? 使用容器中的环境变量 - Use Environment Variables from a container 如何更改 AWS Fargate 上的 Grafana docker 容器环境变量以使用 mysql 数据库 - How do I change Grafana docker container environment variables on AWS Fargate to use a mysql database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM