How to create a https server on localhost

前端 未结 6 488
误落风尘
误落风尘 2021-01-30 08:47

I followed the tutorial below to create a https server https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server/

and the program runs without errors

6条回答
  •  灰色年华
    2021-01-30 09:35

    You need to do two things:

    • generate a self-signed SSL certificate and
    • add it to the trusted certificates

    Managed to do this on a macOS like so:

    • In order to generate the SSL certificate, run the follosing command in a terminal (according to the instructions from Let's Encrypt):
    openssl req -x509 -out localhost.crt -keyout localhost.key \
      -newkey rsa:2048 -nodes -sha256 \
      -subj '/CN=localhost' -extensions EXT -config <( \
       printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
    
    • And to add the certificate to the trusted certificates, ran the following command (suggested on this blog):
    sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "/private/tmp/certs/certname.cer"
    

提交回复
热议问题