2
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の$is_args変数、$args変数とは

Posted at

nginx.confに/hoge$is_args$args;と書いているものがある。

$is_argsとはリクエスト行に引数がある場合は?となり、引数なしの時は空文字列になる。

↓確認

nginx.conf
        location / {
                add_header hoge is_args=${is_args};
        }
$ curl -I localhost
HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Fri, 11 Dec 2020 16:46:06 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: is_args= * 空文字になっている
Accept-Ranges: bytes


$ curl -I localhost?hoge=fuga
HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Fri, 11 Dec 2020 16:46:32 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: is_args=? * はてながついてる
Accept-Ranges: bytes

$argsとはurlに書かれたgetパラメータのこと

↓確認

nginx.conf
        location / {
                add_header hoge is_args=${is_args}${args};
        }
$ curl -I localhost
HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Fri, 11 Dec 2020 16:51:17 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: is_args=
Accept-Ranges: bytes

$ curl -I localhost?a=b
HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Fri, 11 Dec 2020 16:51:32 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: is_args=?a=b
Accept-Ranges: bytes

curl -I localhost?a=b&c=d
[1] 644
[root@ebe2eb08b5b2 ~]# HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Fri, 11 Dec 2020 16:51:47 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: is_args=?a=b * あれc=dが消えてる・・・?
Accept-Ranges: bytes

localhost?a=b&c=dの時にargsにc=dのデータが入らないのが気になる。。。

2
1
1

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
2
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?