<p>I have a working openresty with lua-resty-openidc as ingress controller.
Now, the nginx.conf is hardcoded in my image, with something like this :</p>

<pre><code>    server {
        server_name  _;
        listen       80;

        location /OAuth2Client {
            access_by_lua_block {
                local opts = {
                    discovery = "/.well-known/openid-configuration",
                    redirect_uri = "/authorization-code/callback",
                    client_id = "clientID",
                    client_secret = "clientSecret",
                    scope = "openid profile somethingElse",
                }
    ...
            }
            proxy_pass http://clusterIp/OAuth2Client;
        }
    }
</code></pre>

<p>As Nginx doesn't accept environment variables, is there a simple way to make my nginx.conf configurable, for ex</p>

<pre><code>    server {
        server_name  ${myServerName};
        listen       ${myServerPort};

        location /${specificProjectRoot} {
            access_by_lua_block {
                local opts = {
                    discovery = "${oidc-provider-dev-url}/.well-known/openid-configuration",
                    redirect_uri = "${specificProjectRoot}/authorization-code/callback",
                    client_id = "${myClientId}",
                    client_secret = "${myClientSecret}",
                    scope = "${myScopes}",
                }
    ...
            }
            proxy_pass http://${myClusterIP}/${specificProjectRoot};
        }
    }
</code></pre>

<p>so that whatever team in whatever namespace could reuse my image and just provide a kubernetes secret containing their specific config for their project ?</p>

Aramsham
<p>You would need to render the <code>nginx.conf</code> from a templated version at runtime (as Juliano's comment mentions). To do this, your <code>Dockerfile</code> could look something like this:</p>

<pre><code>FROM nginx
COPY nginx.conf.template /etc/nginx/
CMD ["/bin/bash", "-c", "envsubst &lt; /etc/nginx/nginx.conf.template &gt; /etc/nginx/nginx.conf &amp;&amp; exec nginx -g 'daemon off;'"]
</code></pre>

<p>Notice that it copies <code>nginx.conf.template</code> into your image, this would be your templated config with variables in the form <code>${MY_SERVER_NAME}</code> where <code>MY_SERVER_NAME</code> is <a href="https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables" rel="nofollow noreferrer">injected into your pod as an environment variable</a> via your Kubernetes manifest, from your configmap or secret or however you prefer.</p>
