nginxのconfに変数を定義する
set 変数名 値
で変数を宣言できる。
Contextがserver, location, ifとなっているのでhttpディレクティブの直下には定義できないようだ。
↓公式情報
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set
Syntax: set $variable value;
Default: —
Context: server, location, if
↓確認
nginx.conf
location / {
set $hgoe fuga;
add_header hoge $hoge;
}
$ curl -I localhost
HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Fri, 11 Dec 2020 16:33:12 GMT
Content-Type: text/html
Content-Length: 4057
Last-Modified: Mon, 07 Oct 2019 21:16:24 GMT
Connection: keep-alive
ETag: "5d9bab28-fd9"
hoge: fuga * これ
Accept-Ranges: bytes