Help us understand the problem. What is going on with this article?


More than 5 years have passed since last update.

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

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 が必要なのは手間と言えば手間ですが普通に使えるので機会があれば使ってみてください.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away