質問編集履歴

2

回答を基にコード作成

2019/03/10 12:35

投稿

namuyan
namuyan

スコア76

test CHANGED
File without changes
test CHANGED
@@ -177,3 +177,95 @@
177
177
  ---
178
178
 
179
179
  上記のコードではWSも使用しています。
180
+
181
+
182
+
183
+ 追記2
184
+
185
+ ---
186
+
187
+ 回答を参考にしコードを組んでみましたが動きません。
188
+
189
+ ブラウザでアクセスしてみましたが**安全な接続ができませんでした**と出るだけでエラー番号も出されず先へ進めない状態です。ここからどうすればいいのか教えて下さい。[参考](https://github.com/Raynos/node-http-proxy/blob/f5e1844abd6f7a62d196025e126b6c3fbdbf34ac/README.md)
190
+
191
+ ```js
192
+
193
+ let httpProxy = require('http-proxy'),
194
+
195
+ fs = require('fs'),
196
+
197
+ tls = require("tls");
198
+
199
+
200
+
201
+ function getCredentialsContext(cer) {
202
+
203
+ return tls.createSecureContext({
204
+
205
+ key: fs.readFileSync('/etc/letsencrypt/live/' + cer + '/privkey.pem'),
206
+
207
+ cert: fs.readFileSync('/etc/letsencrypt/live/' + cer + '/fullchain.pem')
208
+
209
+ }).context;
210
+
211
+ }
212
+
213
+
214
+
215
+ let certs = {
216
+
217
+ "domain.tk": getCredentialsContext('domain.tk'),
218
+
219
+ "test.domain.tk": getCredentialsContext('test.domain.tk')
220
+
221
+ };
222
+
223
+ let options = {
224
+
225
+ https: {
226
+
227
+ SNICallback: function(hostname) {
228
+
229
+ return certs[hostname];
230
+
231
+ }
232
+
233
+ },
234
+
235
+ hostnameOnly: true,
236
+
237
+ router: {
238
+
239
+ 'domain.tk': '127.0.0.1:3000',
240
+
241
+ 'test.domain.tk': '127.0.0.1:3000'
242
+
243
+ },
244
+
245
+ target: {
246
+
247
+ https: true // This could also be an Object with key and cert properties
248
+
249
+ }
250
+
251
+ };
252
+
253
+
254
+
255
+ let proxy = httpProxy.createServer(options);
256
+
257
+
258
+
259
+ proxy.on('upgrade', function (req, socket, head) {
260
+
261
+ req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.connection.socket.remoteAddress;
262
+
263
+ proxy.proxy.proxyWebSocketRequest(req, socket, head);
264
+
265
+ });
266
+
267
+
268
+
269
+ proxy.listen(443);
270
+
271
+ ```

1

WS

2019/03/10 12:35

投稿

namuyan
namuyan

スコア76

test CHANGED
File without changes
test CHANGED
@@ -169,3 +169,11 @@
169
169
  ```
170
170
 
171
171
  どのようにコードを組めばいいのかわかる方、参考になりそうな情報を知っている方は回答の方を宜しくお願いします。
172
+
173
+
174
+
175
+ 追記
176
+
177
+ ---
178
+
179
+ 上記のコードではWSも使用しています。