[英]Installing SSL Certificate On Node Server
我創建了一個自簽名證書,並將其安裝在apache以及node.js(端口3000)上。 在localhost上, https://localhost
和https://localhost:3000
運行良好。
因此,我購買了GoDaddy Standard SSL證書並將其安裝在服務器上( http://gatherify.com
)。 現在https://gatherify.com
運行良好,但節點上的ssl無效。 當我訪問https://gatherify.com:3000
我得到“連接被中斷”。
我執行curl:
root@host [~]# curl -v -s -k https://gatherify.com:3000
* About to connect() to gatherify.com port 3000 (#0)
* Trying 108.160.156.123... connected
* Connected to gatherify.com (108.160.156.123) port 3000 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* warning: ignoring value of ssl.verifyhost
* NSS error -5938
* Closing connection #0
* SSL connect error
有什么建議來解決這個問題
更新 * 服務器端: *
var io = require('socket.io'),
connect = require('connect'),
fs = require('fs'),
var privateKey = fs.readFileSync('cert/server.key').toString();
var certificate = fs.readFileSync('cert/server.crt').toString();
var options = {
key: privateKey,
cert: certificate
};
var app = connect(options).use(connect.static('../htdocs/node/'));
app.listen(3000);
var server = io.listen(app);
server.sockets.on('connection', function(socket) {
console.log("Connected");
});
客戶端:
<html> <head>
<script type = "text/javascript" src = "https://gatherify.com:3000/socket.io/socket.io.js"></script>
<script type = "text/javascript">
var socket = io.connect('https://gatherify.com:3000', {secure:true});
</script>
</head><body></body></html>
如果要使用(后面)HTTPS在端口3000上運行node.js應用程序,則需要在端口443上設置代理服務以將HTTPS請求代理到端口3000。
你沒有提到你現在在端口443上運行的服務器(是Apache嗎?)但你可能想要
如果設置正確,用戶可以訪問“ https://gatherify.com ”或“ https://blah.gatherify.com ”(不使用:端口號),並且所有內容都使用SSL保護。 ;)
如果您需要node.js客戶端能夠識別您自己分配或廉價購買的SSL證書,您可以使用ssl-root-cas ,它可以在npm上使用 。
'use strict';
var https = require('https')
, cas
;
// This will add the well-known CAs
// to `https.globalAgent.options.ca`
require('ssl-root-cas').inject();
cas = https.globalAgent.options.ca;
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '01-cheap-ssl-intermediary-a.pem')));
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '02-cheap-ssl-intermediary-b.pem')));
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '03-cheap-ssl-site.pem')));
這將使您的證書可用於核心https
模塊以及依賴它的模塊,例如request
和socket.io-client
而不會刪除正常的ssl證書(由於某些奇怪的原因,這是默認行為)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.