expressjs / vhost

virtual domain hosting
MIT License
761 stars 87 forks source link

each vhost https support #23

Closed shynome closed 7 years ago

shynome commented 7 years ago

how to set ssl cert for each hostname

just like this :

app.use(
  vhost('a.lo.shynome.com',{ cert:'a.lo.shynome.com_bundle.crt',key:'a.lo.shynome.com.crt' },require('./a')),
  vhost('b.lo.shynome.com',{ cert:'b.lo.shynome.com_bundle.crt',key:'b.lo.shynome.com.crt' },require('./b')),
  (req,res)=>res.send('none catch'),
)

Can this be realized?

if you visit https://a.lo.shynome.com/ , Google Chrome will tip u it's unsafe

this is code https://github.com/shynome/vhost-test

dougwilson commented 7 years ago

Hi @shynome , wow I just got the email that this was closed, but somehow missed when it was opened. The two solutions to your issue are:

  1. Use a certificate with a SAN that lists all those alternative domains. This makes the cert valids for all the domains at once, thus making the connection secure for all of them.
  2. Use SNI when you setup your Node.js HTTP server (Node.js supports SNI). This will allow you to keep using individual certs but through SNI the proper cert will be presented to the browser, keeping the connection secure.

I hope this helps!

As for the proposed idea, I'm not sure if that's possible to directly implement in this module, but if you have an idea for how to go about implementing it, always feel free to open a pull request with an implementation or even a written proposal if you're not sure where to start :) !

kevinkassimo commented 6 years ago

Hi @shynome , I know this is closed issue, but I think using tlsSever.addContext() will allow you to configure SNI easily (another way is to use SNICallback). I also quickly implemented a minimal module vhttps that combines virtual host and SNI (although not strictly same as vhost's usage)