質問編集履歴

3

解決の内容を追記

2015/12/14 06:51

投稿

CyberMergina
CyberMergina

スコア295

test CHANGED
File without changes
test CHANGED
@@ -196,6 +196,22 @@
196
196
 
197
197
  }
198
198
 
199
+
200
+
201
+ location /socket/ {
202
+
203
+ proxy_pass http://0.0.0.0:1111/;
204
+
205
+ proxy_http_version 1.1;
206
+
207
+ proxy_set_header Upgrade $http_upgrade;
208
+
209
+ proxy_set_header Connection $connection_upgrade;
210
+
211
+ }
212
+
213
+
214
+
199
215
  }
200
216
 
201
217
 
@@ -265,3 +281,77 @@
265
281
 
266
282
 
267
283
  (※原因はnginxの設定ファイルだと今のところ思っているので、websocketはタグ付けしません。)
284
+
285
+
286
+
287
+
288
+
289
+ ---
290
+
291
+
292
+
293
+ **解決方法**
294
+
295
+
296
+
297
+ 結局、serverのレベルに「X-Forwarded-For」の設定を入れていたので効いていなかったようです。
298
+
299
+ 以下のように location のレベルに指定をいれて動くようになりました。
300
+
301
+ ※nginx.confの「proxy_set_header」は全て削除しました。
302
+
303
+
304
+
305
+ ```conf
306
+
307
+ server {
308
+
309
+ listen 80;
310
+
311
+ server_name hoge.huga.jp;
312
+
313
+
314
+
315
+ location / {
316
+
317
+ proxy_pass http://0.0.0.0:2222;
318
+
319
+ }
320
+
321
+
322
+
323
+ location /socket.io/ {
324
+
325
+ proxy_pass http://0.0.0.0:1111;
326
+
327
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
328
+
329
+ proxy_http_version 1.1;
330
+
331
+ proxy_set_header Upgrade $http_upgrade;
332
+
333
+ proxy_set_header Connection $connection_upgrade;
334
+
335
+ }
336
+
337
+
338
+
339
+ location /socket/ {
340
+
341
+ proxy_pass http://0.0.0.0:1111/;
342
+
343
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
344
+
345
+ proxy_http_version 1.1;
346
+
347
+ proxy_set_header Upgrade $http_upgrade;
348
+
349
+ proxy_set_header Connection $connection_upgrade;
350
+
351
+ }
352
+
353
+
354
+
355
+ }
356
+
357
+ ```

2

ファイルを書き換えてみたので、最新をアップします。

2015/12/14 06:51

投稿

CyberMergina
CyberMergina

スコア295

test CHANGED
File without changes
test CHANGED
@@ -44,121 +44,89 @@
44
44
 
45
45
  ```conf
46
46
 
47
- user nginx;
47
+ user nginx;
48
-
48
+
49
- worker_processes 1;
49
+ worker_processes 1;
50
-
51
-
52
-
50
+
51
+
52
+
53
- error_log /var/log/nginx/error.log warn;
53
+ error_log /var/log/nginx/error.log warn;
54
54
 
55
55
  pid /var/run/nginx.pid;
56
56
 
57
57
 
58
58
 
59
- events {
60
-
61
- worker_connections 1024;
62
-
63
- }
64
-
65
-
66
-
67
- http {
68
-
69
- include /etc/nginx/mime.types;
70
-
71
- default_type application/octet-stream;
72
-
73
-
74
-
75
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
76
-
77
- '$status $body_bytes_sent "$http_referer" '
78
-
79
- '"$http_user_agent" "$http_x_forwarded_for"';
80
-
81
-
82
-
83
- access_log /var/log/nginx/access.log main;
84
-
85
-
86
-
87
- sendfile on;
88
-
89
- #tcp_nopush on;
90
-
91
-
92
-
93
- keepalive_timeout 65;
94
-
95
-
96
-
97
- # ! modified !
98
-
99
- gzip on;
100
-
101
- proxy_buffering on;
102
-
103
- proxy_buffer_size 8k;
104
-
105
- proxy_buffers 100 8k;
106
-
107
-
108
-
109
- server_tokens off;
110
-
111
-
112
-
113
- set_real_ip_from [グローバルIP];
114
-
115
- real_ip_header X-Forwarded-For;
116
-
117
-
118
-
119
- add_header X-XSS-Protection "1; mode=block";
120
-
121
- add_header X-Frame-Options DENY;
122
-
123
- add_header X-Content-Type-Options nosniff;
124
-
125
-
126
-
127
- upstream backend {
128
-
129
- ip_hash;
130
-
131
- server hoge.huga.jp:80;
132
-
133
- server hoge.huga.jp:443;
134
-
135
- server demo.localhost:80;
136
-
137
- server socket.localhost:80;
138
-
139
- server socket.localhost:443;
140
-
141
- }
142
-
143
-
144
-
145
- ## Start: Size Limits & Buffer Overflows ##
146
-
147
- client_body_buffer_size 1K;
148
-
149
- client_header_buffer_size 1k;
150
-
151
- client_max_body_size 5k;
152
-
153
- large_client_header_buffers 2 1k;
154
-
155
- ## END: Size Limits & Buffer Overflows ##
156
-
157
-
158
-
159
- include /etc/nginx/conf.d/*.conf;
160
-
161
- }
59
+
60
+
61
+ events {
62
+
63
+ worker_connections 1024;
64
+
65
+ }
66
+
67
+
68
+
69
+
70
+
71
+ http {
72
+
73
+ include /etc/nginx/mime.types;
74
+
75
+ default_type application/octet-stream;
76
+
77
+
78
+
79
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
80
+
81
+ '$status $body_bytes_sent "$http_referer" '
82
+
83
+ '"$http_user_agent" "$http_x_forwarded_for"';
84
+
85
+
86
+
87
+ access_log /var/log/nginx/access.log main;
88
+
89
+
90
+
91
+ sendfile on;
92
+
93
+ #tcp_nopush on;
94
+
95
+
96
+
97
+ keepalive_timeout 65;
98
+
99
+
100
+
101
+ # ! modified ! #
102
+
103
+ gzip on;
104
+
105
+ proxy_buffering on;
106
+
107
+ proxy_buffer_size 8k;
108
+
109
+ proxy_buffers 100 8k;
110
+
111
+
112
+
113
+ server_tokens off;
114
+
115
+
116
+
117
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
118
+
119
+ proxy_set_header Client-IP $remote_add;
120
+
121
+ proxy_set_header Host $http_host;
122
+
123
+ proxy_redirect off;
124
+
125
+
126
+
127
+ include /etc/nginx/conf.d/*.conf;
128
+
129
+ }
162
130
 
163
131
  ```
164
132
 
@@ -206,20 +174,6 @@
206
174
 
207
175
 
208
176
 
209
- proxy_set_header Host $host;
210
-
211
- proxy_set_header X-Real-IP $remote_addr;
212
-
213
- proxy_set_header X-Remote-Addr $remote_addr;
214
-
215
- proxy_set_header X-Forwarded-Host $host;
216
-
217
- proxy_set_header X-Forwarded-Server $host;
218
-
219
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
220
-
221
-
222
-
223
177
  location / {
224
178
 
225
179
  proxy_set_header Host $http_host;
@@ -254,20 +208,6 @@
254
208
 
255
209
 
256
210
 
257
- proxy_set_header Host $host;
258
-
259
- proxy_set_header X-Real-IP $remote_addr;
260
-
261
- proxy_set_header X-Remote-Addr $remote_addr;
262
-
263
- proxy_set_header X-Forwarded-Host $host;
264
-
265
- proxy_set_header X-Forwarded-Server $host;
266
-
267
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
268
-
269
-
270
-
271
211
  location / {
272
212
 
273
213
  proxy_pass http://0.0.0.0:2222;
@@ -298,4 +238,30 @@
298
238
 
299
239
 
300
240
 
241
+ **socket_ctrl.js**
242
+
243
+
244
+
245
+ ```javascript
246
+
247
+ ~ 省略 ~
248
+
249
+
250
+
251
+ //接続確立時の処理
252
+
253
+ connect = io.sockets.on('connection', function (socket) {
254
+
255
+
256
+
257
+ // 接続時
258
+
259
+ socket.on('connected', function (r) {
260
+
261
+ console.log(socket.handshake); // ひとまずここでヘッダー情報をとれるか確認してます。
262
+
263
+ ```
264
+
265
+
266
+
301
267
  (※原因はnginxの設定ファイルだと今のところ思っているので、websocketはタグ付けしません。)

1

タイトル少し変えました

2015/12/10 01:06

投稿

CyberMergina
CyberMergina

スコア295

test CHANGED
@@ -1 +1 @@
1
- nginxでリバースプロキシを使った際に取得したIPアドレスが127.0.0.1になってしまう
1
+ nginxでリバースプロキシを使った際に取得したIPアドレスが127.0.0.1になっている
test CHANGED
File without changes