About HTTPS
HTTPS: (Full name: Hypertext Transfer Protocol over secure Socket Layer), is a security-targeted HTTP channel, simply speaking is the security version of HTTP. That is, the SSL layer is added under HTTP, the security base of HTTPS is SSL, so the detailed content of encryption needs SSL. It is a URI scheme (abstract identifier system) with syntax similar to http: System. For secure HTTP data transfer. In addition, the HTTP interface is not allowed in HTTPS sites.
the difference between HTTPS and HTTP
The HTTPS protocol requires a certificate to be applied to the CA, and the general free certificate is very small and requires a fee.
HTTP is a Hypertext Transfer Protocol, the information is plaintext transmission, HTTPS is a secure SSL encryption transport protocol.
HTTP and HTTPS use a completely different connection, the same port, the former is 80, the latter is 443.
The HTTP connection is simple and stateless; The HTTPS protocol is a network protocol built by the SSL+HTTP protocol for encrypted transmission and authentication, which is more secure than the HTTP protocol.
OpenSSL generates a certificate file
As long as the Git client is installed, there will be OpenSSL
Detect if OpenSSL is installed
OpenSSL version-a
Next, start generating the certificate:
#1#2, generate CSR certificate signature via private key -new-key Privatekey.pem- Out certrequest.csr#3-req- in Certrequest.csr-signkey privatekey.pem-out Certificate.pem
After executing the third command you will see:
Signature ok
表示生成成功,最终看到如下三个文件
PRIVATEKEY.PEM: Private key
Certrequest.csr:CSR Certificate Signing
CERTIFICATE.PEM: Certificate file
node. js modifies the startup file: App.js
~ VI app.js// bottom var https = require (' https ') = require ("FS"); var options = { key:fs.readFileSync ('./privatekey.pem '), Cert:fs.readFileSync ( './certificate.pem ')};https.createserver (options, App). Listen (function () { console.log (' HTTPS server listening on port ' + 3011 ');
Start the server:
Express server listening on port 3000
Https server listening on port 3011
FAQ: 1, Failed to load Resource:net::err_insecure_response
This is because you use the certificate is not normal, let the browser to intercept, open your console and click on the inside URL. It will take you to the API page, then accept the SSL certificate on the page, return to your app page and reload.
node. JS builds HTTPS server