node. JS builds HTTPS server

Source: Internet
Author: User
Tags generate csr openssl version csr certificate git client ssl certificate

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.