回答編集履歴
2
回答が誤っていたので、修正した。
answer
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
[Module ngx_http_realip_module](http://nginx.org/en/docs/http/ngx_http_realip_module.html)を使用されているようですが、
|
2
|
-
これは指定したHTTPヘッダ
|
2
|
+
これは指定したHTTPヘッダから、nginxへの接続元のアドレスを取得するもので、nginxの手前にプロクシなどがある場合に使用するものです。
|
3
|
-
|
3
|
+
今回は、nginxの手前には何もないと思いますので、関係ありません。
|
4
|
+
そのため、以下の設定は不要と思います。
|
4
5
|
```
|
6
|
+
set_real_ip_from [グローバルIP];
|
5
7
|
real_ip_header X-Forwarded-For;
|
6
8
|
```
|
7
|
-
を指定しているので、HTTPヘッダのX-Forwarded-Forにアドレスが渡ります。
|
8
9
|
|
10
|
+
|
11
|
+
逆に、以下のページにあるように、
|
12
|
+
自分でX-FORWARDED-FORなどに、nginxへの接続元のアドレスを設定する必要があります。
|
13
|
+
```
|
14
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
15
|
+
```
|
16
|
+
[centos7 - nginx でアクセス元のIPを正しく表示させる方法 - Qiita](http://qiita.com/yakumo3/items/dc38a9b6c19194a88922)
|
17
|
+
|
9
|
-
`handshake.address`は直接のTCP接続元を取得するもののようなので、
|
18
|
+
さらに、`handshake.address`は直接のTCP接続元を取得するもののようなので、
|
10
19
|
HTTPヘッダをみるには、
|
11
20
|
以下にあるように、`handshake.headers['x-forwarded-for']`を使うべきです。
|
12
21
|
|
13
|
-
[express - How to get request’s HTTP headers with Socket.io? - Stack Overflow](http://stackoverflow.com/questions/13573016/how-to-get-request-s-http-headers-with-socket-io)
|
22
|
+
[express - How to get request’s HTTP headers with Socket.io? - Stack Overflow](http://stackoverflow.com/questions/13573016/how-to-get-request-s-http-headers-with-socket-io)
|
23
|
+
|
1
説明を詳細化した。
answer
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
[Module ngx_http_realip_module](http://nginx.org/en/docs/http/ngx_http_realip_module.html)を使用されているようですが、
|
2
|
-
これは指定したHTTPヘッダに、
|
2
|
+
これは指定したHTTPヘッダに、nginxへの接続元のアドレスを渡してくれるものです。
|
3
3
|
|
4
|
+
```
|
5
|
+
real_ip_header X-Forwarded-For;
|
6
|
+
```
|
7
|
+
を指定しているので、HTTPヘッダのX-Forwarded-Forにアドレスが渡ります。
|
8
|
+
|
4
|
-
`handshake.address`は直接のTCP接続元を取得するもののようなので、
|
9
|
+
`handshake.address`は直接のTCP接続元を取得するもののようなので、
|
10
|
+
HTTPヘッダをみるには、
|
5
11
|
以下にあるように、`handshake.headers['x-forwarded-for']`を使うべきです。
|
6
12
|
|
7
13
|
[express - How to get request’s HTTP headers with Socket.io? - Stack Overflow](http://stackoverflow.com/questions/13573016/how-to-get-request-s-http-headers-with-socket-io)
|