Yan Li
Yan Li

Reputation: 1819

node.js https example ,error, Unknown SSL protocol error in connection to localhost

I use simple example from these link:

a link[a How to create an HTTPS server in Node.js?]

a link[a How to create an https server? docs.nodejitsu.com]

but I get error like

curl: (35) Unknown SSL protocol error in connection to localhost:-9838

why?

Upvotes: 28

Views: 21246

Answers (2)

yegor256
yegor256

Reputation: 105143

This is a faster way to do the same:

$ openssl req -new -newkey rsa:4096 -days 9999 -nodes -x509 \
  -subj "/C=US/O=Example Inc./CN=example.com" \
  -keyout key.pem -out cert.pem

Upvotes: 0

Yan Li
Yan Li

Reputation: 1819

I use the wrong way to create certificate.

This one is wrong:

openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem

This is the way to create certificate that could use:

openssl genrsa -out client-key.pem 2048
openssl req -new -key client-key.pem -out client.csr
openssl x509 -req -in client.csr -signkey client-key.pem -out client-cert.pem

Upvotes: 81

Related Questions