質問編集履歴
3
解決の内容を追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -97,6 +97,14 @@
|
|
97
97
|
proxy_set_header Upgrade $http_upgrade;
|
98
98
|
proxy_set_header Connection $connection_upgrade;
|
99
99
|
}
|
100
|
+
|
101
|
+
location /socket/ {
|
102
|
+
proxy_pass http://0.0.0.0:1111/;
|
103
|
+
proxy_http_version 1.1;
|
104
|
+
proxy_set_header Upgrade $http_upgrade;
|
105
|
+
proxy_set_header Connection $connection_upgrade;
|
106
|
+
}
|
107
|
+
|
100
108
|
}
|
101
109
|
|
102
110
|
server {
|
@@ -131,4 +139,41 @@
|
|
131
139
|
console.log(socket.handshake); // ひとまずここでヘッダー情報をとれるか確認してます。
|
132
140
|
```
|
133
141
|
|
134
|
-
(※原因はnginxの設定ファイルだと今のところ思っているので、websocketはタグ付けしません。)
|
142
|
+
(※原因はnginxの設定ファイルだと今のところ思っているので、websocketはタグ付けしません。)
|
143
|
+
|
144
|
+
|
145
|
+
---
|
146
|
+
|
147
|
+
**解決方法**
|
148
|
+
|
149
|
+
結局、serverのレベルに「X-Forwarded-For」の設定を入れていたので効いていなかったようです。
|
150
|
+
以下のように location のレベルに指定をいれて動くようになりました。
|
151
|
+
※nginx.confの「proxy_set_header」は全て削除しました。
|
152
|
+
|
153
|
+
```conf
|
154
|
+
server {
|
155
|
+
listen 80;
|
156
|
+
server_name hoge.huga.jp;
|
157
|
+
|
158
|
+
location / {
|
159
|
+
proxy_pass http://0.0.0.0:2222;
|
160
|
+
}
|
161
|
+
|
162
|
+
location /socket.io/ {
|
163
|
+
proxy_pass http://0.0.0.0:1111;
|
164
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
165
|
+
proxy_http_version 1.1;
|
166
|
+
proxy_set_header Upgrade $http_upgrade;
|
167
|
+
proxy_set_header Connection $connection_upgrade;
|
168
|
+
}
|
169
|
+
|
170
|
+
location /socket/ {
|
171
|
+
proxy_pass http://0.0.0.0:1111/;
|
172
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
173
|
+
proxy_http_version 1.1;
|
174
|
+
proxy_set_header Upgrade $http_upgrade;
|
175
|
+
proxy_set_header Connection $connection_upgrade;
|
176
|
+
}
|
177
|
+
|
178
|
+
}
|
179
|
+
```
|
2
ファイルを書き換えてみたので、最新をアップします。
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,64 +21,48 @@
|
|
21
21
|
**nginx.conf**
|
22
22
|
|
23
23
|
```conf
|
24
|
-
user nginx;
|
24
|
+
user nginx;
|
25
|
-
worker_processes 1;
|
25
|
+
worker_processes 1;
|
26
|
-
|
26
|
+
|
27
|
-
error_log /var/log/nginx/error.log warn;
|
27
|
+
error_log /var/log/nginx/error.log warn;
|
28
28
|
pid /var/run/nginx.pid;
|
29
29
|
|
30
|
+
|
30
|
-
events {
|
31
|
+
events {
|
31
|
-
worker_connections 1024;
|
32
|
+
worker_connections 1024;
|
32
33
|
}
|
33
34
|
|
35
|
+
|
34
|
-
http {
|
36
|
+
http {
|
35
|
-
include /etc/nginx/mime.types;
|
37
|
+
include /etc/nginx/mime.types;
|
36
|
-
default_type application/octet-stream;
|
38
|
+
default_type application/octet-stream;
|
37
|
-
|
39
|
+
|
38
|
-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
40
|
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
39
|
-
'$status $body_bytes_sent "$http_referer" '
|
41
|
+
'$status $body_bytes_sent "$http_referer" '
|
40
|
-
'"$http_user_agent" "$http_x_forwarded_for"';
|
42
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
41
|
-
|
43
|
+
|
42
|
-
access_log /var/log/nginx/access.log main;
|
44
|
+
access_log /var/log/nginx/access.log main;
|
43
|
-
|
45
|
+
|
44
|
-
sendfile on;
|
46
|
+
sendfile on;
|
45
|
-
#tcp_nopush on;
|
47
|
+
#tcp_nopush on;
|
46
|
-
|
48
|
+
|
47
|
-
keepalive_timeout 65;
|
49
|
+
keepalive_timeout 65;
|
48
|
-
|
50
|
+
|
49
|
-
# ! modified !
|
51
|
+
# ! modified ! #
|
50
|
-
gzip on;
|
52
|
+
gzip on;
|
51
|
-
proxy_buffering on;
|
53
|
+
proxy_buffering on;
|
52
|
-
proxy_buffer_size 8k;
|
54
|
+
proxy_buffer_size 8k;
|
53
|
-
proxy_buffers 100 8k;
|
55
|
+
proxy_buffers 100 8k;
|
54
|
-
|
56
|
+
|
55
|
-
server_tokens off;
|
57
|
+
server_tokens off;
|
56
|
-
|
58
|
+
|
57
|
-
|
59
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
58
|
-
|
60
|
+
proxy_set_header Client-IP $remote_add;
|
59
|
-
|
60
|
-
add_header X-XSS-Protection "1; mode=block";
|
61
|
-
add_header X-Frame-Options DENY;
|
62
|
-
add_header X-Content-Type-Options nosniff;
|
63
|
-
|
64
|
-
upstream backend {
|
65
|
-
ip_hash;
|
66
|
-
server hoge.huga.jp:80;
|
67
|
-
server hoge.huga.jp:443;
|
68
|
-
server demo.localhost:80;
|
69
|
-
|
61
|
+
proxy_set_header Host $http_host;
|
70
|
-
|
62
|
+
proxy_redirect off;
|
63
|
+
|
64
|
+
include /etc/nginx/conf.d/*.conf;
|
71
|
-
|
65
|
+
}
|
72
|
-
|
73
|
-
## Start: Size Limits & Buffer Overflows ##
|
74
|
-
client_body_buffer_size 1K;
|
75
|
-
client_header_buffer_size 1k;
|
76
|
-
client_max_body_size 5k;
|
77
|
-
large_client_header_buffers 2 1k;
|
78
|
-
## END: Size Limits & Buffer Overflows ##
|
79
|
-
|
80
|
-
include /etc/nginx/conf.d/*.conf;
|
81
|
-
}
|
82
66
|
```
|
83
67
|
|
84
68
|
|
@@ -102,13 +86,6 @@
|
|
102
86
|
listen 80;
|
103
87
|
server_name hoge.huga.jp;
|
104
88
|
|
105
|
-
proxy_set_header Host $host;
|
106
|
-
proxy_set_header X-Real-IP $remote_addr;
|
107
|
-
proxy_set_header X-Remote-Addr $remote_addr;
|
108
|
-
proxy_set_header X-Forwarded-Host $host;
|
109
|
-
proxy_set_header X-Forwarded-Server $host;
|
110
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
111
|
-
|
112
89
|
location / {
|
113
90
|
proxy_set_header Host $http_host;
|
114
91
|
proxy_pass http://0.0.0.0:2222;
|
@@ -126,13 +103,6 @@
|
|
126
103
|
listen 443;
|
127
104
|
server_name hoge.huga.jp;
|
128
105
|
|
129
|
-
proxy_set_header Host $host;
|
130
|
-
proxy_set_header X-Real-IP $remote_addr;
|
131
|
-
proxy_set_header X-Remote-Addr $remote_addr;
|
132
|
-
proxy_set_header X-Forwarded-Host $host;
|
133
|
-
proxy_set_header X-Forwarded-Server $host;
|
134
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
135
|
-
|
136
106
|
location / {
|
137
107
|
proxy_pass http://0.0.0.0:2222;
|
138
108
|
proxy_http_version 1.1;
|
@@ -148,4 +118,17 @@
|
|
148
118
|
}
|
149
119
|
```
|
150
120
|
|
121
|
+
**socket_ctrl.js**
|
122
|
+
|
123
|
+
```javascript
|
124
|
+
~ 省略 ~
|
125
|
+
|
126
|
+
//接続確立時の処理
|
127
|
+
connect = io.sockets.on('connection', function (socket) {
|
128
|
+
|
129
|
+
// 接続時
|
130
|
+
socket.on('connected', function (r) {
|
131
|
+
console.log(socket.handshake); // ひとまずここでヘッダー情報をとれるか確認してます。
|
132
|
+
```
|
133
|
+
|
151
134
|
(※原因はnginxの設定ファイルだと今のところ思っているので、websocketはタグ付けしません。)
|
1
タイトル少し変えました
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
nginxでリバースプロキシを使った際に取得したIPアドレスが127.0.0.1になって
|
1
|
+
nginxでリバースプロキシを使った際に取得したIPアドレスが127.0.0.1になっている
|
body
CHANGED
File without changes
|