简体   繁体   English

可以使用express在node.js中以相同的端口号运行http和https服务器吗?

[英]Is possible to run http and https server with same port no in node.js using express?

I have two server HTTP and HTTPS with key.Once I authenticated then I need to change Http to HTTPS at the same port.. 我有两个带有密钥的服务器HTTP和HTTPS。一旦通过身份验证,则需要在同一端口将Http更改为HTTPS。

var httpsoptions={
key:fs.readFileSync('./keys/twc-key.pem'),
cert:fs.readFileSync('./keys/twc-cert.pem')
};

var webServer = express();    
var websecure = express(httpoptions);  

Here I need to maintain same port for both Http and Https how is possible? 在这里,我需要为Http和Https维护相同的端口,怎么可能?

Use Nginx as a reverse proxy 使用Nginx作为反向代理

  • You can enable HTTPs on nginx, and proxy your node application through nginx. 您可以在nginx上启用HTTP,并通过nginx代理您的节点应用程序。

Use the express-vhost middleware 使用express-vhost中间件

  • Use express-vhost and host https on a subdomain 在子域上使用express-vhost并托管https
  • eg. 例如。 https://secure.url.com
  • or https://login.url.com https://login.url.com

Use port 443 使用端口443

  • Easier yet! 更容易了!
  • 443 is accepted as a default port for https by basically all browsers. 基本上所有浏览器都将443用作https的默认端口。 Some call it deprecated, but I've seen nothing supporting this claim. 有人称它已被弃用,但我看不出有什么理由支持这一说法。
  • 443 is still accepted as the default port for https. 仍将443作为https的默认端口。

Host everything over https 通过https托管所有内容

  • Many sites do this already 许多网站已经这样做了
  • Prevents session hijacking 防止会话劫持
  • Prevents token hijacking 防止令牌劫持
  • Prevents MITM attacks 防止MITM攻击
  • Even if you just have the log in secure, afterward your cookies are in plain text in your http header. 即使您只是安全登录,之后,您的Cookie仍以纯文本形式出现在http标头中。 An attacker could steal the session cookie and hijack the users session. 攻击者可能窃取会话cookie并劫持用户会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM