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

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

More than 3 years have passed since last update.

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

Why do not you register as a user and use Qiita more conveniently?
  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
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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