openresty / docker-openresty

Docker tooling for OpenResty
https://hub.docker.com/r/openresty/openresty
BSD 2-Clause "Simplified" License
935 stars 525 forks source link

environment variable injected by docker compose is not available in openresty process #247

Closed kertL closed 6 months ago

kertL commented 6 months ago

I'm using openresty/openresty:1.19.3.1-8-centos7 image. There're some lines like below in the compose yml file used to start container,

`
environment:

in nginx.conf file, I have some lua code to retrieve it,

set_by_lua_block $ssl_header{ return os.getenv("SSL_IMPL") or "unknown" }

But the retrieved value is always "unknown".

I entered the container using docker exec /bin/sh, and I can see the SSL_IMPL variable does exist in the shell.

` admin@origin-dev:/mnt/fastmock$ docker exec fastmock_nginx_1 /bin/sh -c export | grep SSL export SSL_IMPL="openssl_1.1.1"

`

However, the environ file under /proc for openresty process seems incomplete,

admin@origin-dev:/mnt/fastmock$ docker exec fastmock_nginx_1 cat /proc/1/environ nresty -g daemon off;

Is there any workaround to make the environment variable available?

Thanks in advance.

neomantra commented 6 months ago

I think the issue is that you need to expose that environment variable in your nginx setup with the env directive. Without it, nginx strips environment variables for security.

kertL commented 6 months ago

It works. Thank you!