Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

https

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?

like image 940
Yan Li Avatar asked Jan 17 '16 06:01

Yan Li


People also ask

How do I run HTTPS on localhost node JS?

To start your https server, run node app. js (here, app. js is name of the file) on the terminal. or in your browser, by going to https://localhost:8000 .

What is http and HTTPS in node JS?

HTTP: When the data transfer in HTTP protocol it just travels in the clear text format. HTTPS: It simply makes encryption when the request is traveling from the browser to the web server so it is tough to sniff that information.


1 Answers

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
like image 121
Yan Li Avatar answered Oct 05 '22 09:10

Yan Li