1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

nginxのconfに変数を定義する

Posted at

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
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?