nodejs - error self signed certificate in certificate chain

前端 未结 6 1748
孤街浪徒
孤街浪徒 2020-12-07 22:51

I am facing a problem with client side https requests.

A snippet can look like this:

var fs = require(\'fs\');
var https = require(\'https\');

var o         


        
6条回答
  •  悲哀的现实
    2020-12-07 23:32

    From your question I'm guessing you are doing this in development as you are using a self signed certificate for SSL communication.

    If that's the case, add NODE_TLS_REJECT_UNAUTHORIZED='0' as an environment variable wherever you are running node or running node directly with NODE_TLS_REJECT_UNAUTHORIZED='0' node app.js

    This instructs Node to allow untrusted certificates (untrusted = not verified by a certificate authority)

    If you don't want to set an environment variable or need to do this for multiple applications npm has a configuration you can set using the command npm config set strict-ssl=false

    I would not recommend setting this environment variable in production. Use a free SSL cert from a trusted provider like letsencrypt.org

提交回复
热议问题