简体   繁体   中英

Node.js HTTPS server not responding when using RapidSSL certificate

I'm trying to use SSL and HTTPS with my Node.js app running on Amazon EC2. I've purchased a RapidSSL certificate through Name.com , and followed the instructions at this StackOverflow answer to set up the server correctly for HTTPS. Here's the relevant code:

var http = require('http'),
  https = require('https');
var express = require("express"),
  app = express();
var fs = require('fs');

...
app.set('certificate', fs.readFileSync('/path/to/cert.pem', 'utf8'));
app.set('privateKey', fs.readFileSync('/path/to/privateKey.pem', 'utf8'));
...

http.createServer(app).listen(app.get('port'), function() {
  console.info('Listening on port %d', app.get('port'));
});
var options = {key: app.get('privateKey'), cert: app.get('certificate')};
https.createServer(options, app).listen(app.get('sslPort'), function() {
  console.info('HTTPS listening on port %d', app.get('sslPort'));
});

When I run the server locally with a self-signed certificate, everything behaves normally after ignoring the security warnings. When I deploy the code to the EC2 instance, however, the program runs without giving errors, but when I go to the domain using HTTPS, the server doesn't return anything, and the browser times out. Requesting the site with HTTP still works normally.

I've tried this in Chrome, as well as with cURL. The certificate was issued for the www subdomain, but according to Name.com it should work with the root domain as well. I've tried querying the site on both the subdomain and the root domain, to the same effect.

Thanks in advance for any help.

Turns out, I hadn't allowed incoming traffic from port 443 in the security group in the EC2 dashboard. Allowing that from 0.0.0.0/0 made SSL work. I solved this a while ago, but forgot about the question, so here's the answer for anyone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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