Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx の設定ファイルで環境変数を展開できるようにする #44

Closed
tichi73 opened this issue Aug 9, 2024 · 0 comments
Closed
Assignees

Comments

@tichi73
Copy link
Contributor

tichi73 commented Aug 9, 2024

nginx の設定ファイルで環境変数を参照できるようにしたい。具体的には upstream django のサーバ指定を例えば以下のように環境変数で指定しておきたい。(クラスタ構成で同じノードの kompira コンテナに接続するようにしたいが、これは別課題で扱う予定)

upstream django {
    server ${KOMPIRA_HOST}:${KOMPIRA_PORT};
}

nginx の設定ファイル上では直接環境変数を参照するような記述はできないが、docker-nginx では起動時に envsubst コマンドを用いてテンプレートを環境変数展開して設定ファイルを出力する機構が備わっており、これを利用できるようにする。

https://github.com/nginxinc/docker-nginx/blob/master/entrypoint/20-envsubst-on-templates.sh

これはテンプレートとなる設定ファイルを /etc/nginx/templates/*.template として配置しておけば、環境変数を展開して /etc/nginx/conf.d/* に設定ファイルを書き出してくれる。

@tichi73 tichi73 self-assigned this Aug 9, 2024
tichi73 added a commit that referenced this issue Aug 20, 2024
@tichi73 tichi73 closed this as completed Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant