簡體   English   中英

在節點服務器上安裝SSL證書

[英]Installing SSL Certificate On Node Server

我創建了一個自簽名證書,並將其安裝在apache以及node.js(端口3000)上。 在localhost上, https://localhosthttps://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嗎?)但你可能想要

  1. 將該服務移動到新端口(例如4000),然后在端口443上運行處理HTTPS的節點http代理
  2. 然后為您在端口3000上運行的node.js應用程序設置子域(例如blah.gatherify.com)。
  3. 然后,使用節點http代理 ,您將代理所有對“gatherify.com”發送到端口4000的請求,以及對“blah.gatherify.com”發送到端口3000的所有請求。

如果設置正確,用戶可以訪問“ https://gatherify.com ”或“ https://blah.gatherify.com ”(不使用:端口號),並且所有內容都使用SSL保護。 ;)

安裝證書客戶端(在Node.js中)

如果您需要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模塊以及依賴它的模塊,例如requestsocket.io-client而不會刪除正常的ssl證書(由於某些奇怪的原因,這是默認行為)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM