2017-02-28 176 views
1

創建自簽名證書,在Chrome開啓不安全的本地主機之後: 鉻://標誌/#允許不安全,本地主機HTTPS服務器自簽名證書

並添加自簽名證書系統後'相信所有'。下面的代碼仍然不通過https託管服務器。 顯示在鍍鉻以下錯誤:

This site can’t provide a secure connection 

localhost sent an invalid response. 
Try running Network Diagnostics. 
ERR_SSL_PROTOCOL_ERROR 

我缺少的是這個工作?

var express = require('express'); 
var https = require('https'); 
var http = require('http'); 
var fs = require('fs'); 

// This line is from the Node.js HTTPS documentation. 
var options = { 
    key: fs.readFileSync('key.pem'), 
    cert: fs.readFileSync('cert.pem') 
}; 

// Create a service (the app object is just a callback). 
var app = express(); 

// Create an HTTP service. 
http.createServer(app).listen(8000); 
// Create an HTTPS service identical to the HTTP service. 
https.createServer(options, app).listen(8001); 
+0

你連接到正確的端口? 'https:// localhost:8001/...' – robertklep

+0

是的,我衝浪到https:// localhost:8001/ – Vincent

+0

您的證書是CN'localhost'嗎?即'CN = localhost' – wablab

回答

3

創建證書(遵循http://www.akadia.com/services/ssh_test_certificate.html)和添加它來鑰匙串訪問爲我工作在Mac

openssl genrsa -des3 -out server.key 1024 
    openssl req -new -key server.key -out server.csr 
    cp server.key server.key.org 
    openssl rsa -in server.key.org -out server.key 
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt 
+0

這些爲Mac的步驟在搜索Internet兩小時後製作了一個竅門。感謝@Vincent!我之前使用的是https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server/說明和證書無效的步驟。 –

0

我遇到了類似的問題,當我不小心擦掉了我的openssl-serial文件。從那時起頒發的所有證書都以已發佈的連續劇開始。如果客戶注意到該客戶已經看到一個序列號的證書,該證書將不會被接受,連接也不會建立。

雖然我不知道是否是這個問題(也許你跟蹤你的日誌的詳細錯誤)。