【发布时间】:2020-04-09 07:56:22
【问题描述】:
我有一个使用 lua-resty-openidc 作为入口控制器的 openresty。 现在,nginx.conf 在我的图像中被硬编码,如下所示:
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;
}
}
由于 Nginx 不接受环境变量,有没有一种简单的方法可以让我的 nginx.conf 可配置,例如
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};
}
}
这样任何命名空间中的任何团队都可以重用我的图像,并且只需提供一个包含其项目特定配置的 kubernetes 机密?
【问题讨论】:
-
如果你创建一个“start_script.sh”来在你的 nginx 启动时运行呢?在脚本中,您可以使用环境变量并使用
sed您可以替换 nginx.conf 中的值。类似的东西:sed -i -e "s,\${myServerName},$SERVER_NAME," /etc/nginx/nginx.conf
标签: nginx kubernetes openresty