@@ -293,6 +293,67 @@ http.createServer(function (req, res) {
293
293
}).listen (8000 );
294
294
```
295
295
296
+ ### Using two certificates
297
+
298
+ Suppose that your reverse proxy will handle HTTPS traffic for two different domains ` fobar.com ` and ` barbaz.com ` .
299
+ If you need to use two different certificates you can take advantage of [ Server Name Indication] ( http://en.wikipedia.org/wiki/Server_Name_Indication ) .
300
+
301
+ ``` js
302
+ var https = require (' https' ),
303
+ path = require (" path" ),
304
+ fs = require (" fs" ),
305
+ crypto = require (" crypto" );
306
+
307
+ //
308
+ // generic function to load the credentials context from disk
309
+ //
310
+ function getCredentialsContext (cer ){
311
+ return crypto .createCredentials ({
312
+ key: fs .readFileSync (path .join (__dirname , ' certs' , cer + ' .key' )),
313
+ cert: fs .readFileSync (path .join (__dirname , ' certs' , cer + ' .crt' ))
314
+ }).context ;
315
+ }
316
+
317
+ //
318
+ // A certificate per domain hash
319
+ //
320
+ var certs = {
321
+ " fobar.com" : getCredentialsContext (" foobar" ),
322
+ " barbaz.com" : getCredentialsContext (" barbaz" )
323
+ };
324
+
325
+ //
326
+ // Proxy options
327
+ //
328
+ var options = {
329
+ https: {
330
+ SNICallback : function (hostname ){
331
+ return certs[hostname];
332
+ }
333
+ },
334
+ hostnameOnly: true ,
335
+ router: {
336
+ ' fobar.com' : ' 127.0.0.1:8001' ,
337
+ ' barbaz.com' : ' 127.0.0.1:8002'
338
+ }
339
+ };
340
+
341
+ //
342
+ // Create a standalone HTTPS proxy server
343
+ //
344
+ httpProxy .createServer (options).listen (8001 );
345
+
346
+ //
347
+ // Create the target HTTPS server
348
+ //
349
+ http .createServer (function (req , res ) {
350
+ res .writeHead (200 , { ' Content-Type' : ' text/plain' });
351
+ res .write (' hello https\n ' );
352
+ res .end ();
353
+ }).listen (8000 );
354
+
355
+ ```
356
+
296
357
### Proxying to HTTPS from HTTPS
297
358
Proxying from HTTPS to HTTPS is essentially the same as proxying from HTTPS to HTTP, but you must include the ` target ` option in when calling ` httpProxy.createServer ` or instantiating a new instance of ` HttpProxy ` .
298
359
0 commit comments