2013-03-10 120 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證書(這是一些奇怪的原因默認行爲)模塊。