2013-03-10 99 views
2

我创建了一个自签名证书,并将其安装在apache以及node.js(端口3000)上。在本地主机上,https://localhosthttps://localhost:3000都能正常工作。在节点服务器上安装SSL证书

因此,我购买了GoDaddy Standard SSL证书并将其安装在服务器上(http://gatherify.com)。现在https://gatherify.com工作正常,但节点上的ssl不起作用。 当我访问https://gatherify.com:3000时,我得到“连接中断”。

我执行卷曲:

[email protected] [~]# 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 

任何建议,以解决这一问题?

UPDATE * 服务器端: *

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> 
+0

该主机上的端口3000不使用SSL,只是普通的HTTP,因此使用https URL访问它将失败。 – 2013-03-10 17:05:05

+0

你有'key'和'crt'证书文件吗? – udidu 2013-03-10 17:06:19

+0

@JoachimIsaksson那么,我该如何解决这个问题? – Praveen 2013-03-10 17:20:28

回答

2

如果你想运行在端口3000的node.js应用程序与(后面)HTTPS,那么您需要在端口443上设置代理服务来代理到por的HTTPS请求牛逼3000

你没有提到你已经在端口443上运行的服务器,现在(是Apache的?),但你可能要

  1. 此举的服务,新的端口(例如4000),然后在处理HTTPS的端口443上运行node http proxy
  2. 然后为您在端口3000上运行的node.js应用程序(例如blah.gatherify.com)设置一个子域。
  3. 然后,使用node http proxy,你会代理这都是为了“gatherify.com”到端口4000的所有请求,而且这都是为了“blah.gatherify.com”到端口3000

所有请求当所有设置都正确时,用户可以访问“https://gatherify.com”或“https://blah.gatherify.com”(不使用:端口号),它将全部使用SSL进行保护。 ;)

+0

我做了另一种方式,我的意思是在Apache上运行代理并重定向到节点服务器。我的web浏览器中的web应用程序正在通过https完美工作(将请求从apache正确地重定向到节点),但是我们的iOS和android应用程序未连接到节点....如果您有任何关于它的经验/信息,请指导我。谢谢:) – 2016-04-13 06:43:43

+0

它应该在所有使用HTTP的设备上都一样。所以,iOS,Android,Desktop,Laptop,他们都应该能够连接。如果它在您的桌面浏览器中运行,我不确定为什么它不在您的移动浏览器中,除非您有一些用户代理重定向或仅适用于移动用户代理的内容。 – trusktr 2016-04-14 04:50:40

2

安装证书的客户端(在Node.js的)

如果你需要一个Node.js的客户端能够识别你的自我分配的或便宜买来的SSL证书,您可以使用ssl-root-cas,这是available on 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证书(这是一些奇怪的原因默认行为)模块。