LoginSignup
11
14

More than 5 years have passed since last update.

Nginxの設定内で環境変数を使いたい

Posted at

Nginx の設定内では環境変数を読み込むことは基本的にできません.しかし lua-nginx-module を使うと環境変数を読み込むことができます.やり方を簡単に紹介します.

nginx.conf
env PATH;

set_by_lua $upstream 'return os.getenv("PATH")..":9000"';

引き継ぎたい環境変数は env で指定をする必要があります.指定しないと以下の様なエラーが出ます.

[error] 7#0: *1 failed to run set_by_lua*: set_by_lua:1: attempt to concatenate a nil value
stack traceback:
        set_by_lua:1: in function <set_by_lua:1>, ...

文字列結合は .. を使います.一々環境変数を取得するだけで lua が必要なのは手間と言えば手間ですが普通に使えるので機会があれば使ってみてください.

11
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
14