"拒绝连接"用https和let-encyrpt

时间:2018-06-14 09:24:07

标签: node.js express ssl https lets-encrypt

我已成功通过letsencrypt.org为我的网站创建了SSL证书和密钥。我将它们上传到服务器上的文件夹中。启动服务器时没有错误。

但是当我尝试使用https://在浏览器中加载网站时,我得到了#34;拒绝连接"错误。

以下是我用来创建https服务器的代码:

'use strict';

const express = require('express');
const fs =  require('fs');
const http=  require('http');
const https=  require('https');
const path = require('path');

const PRIVATEKEY_PATH = path.join(__dirname, '../ssl/server.key');
const CERTIFICATE_PATH = path.join(__dirname, '../ssl/server.crt');

var privateKey  = fs.readFileSync(PRIVATEKEY_PATH, 'utf8');
var certificate = fs.readFileSync(CERTIFICATE_PATH, 'utf8');
var credentials = {key: privateKey, cert: certificate};

// Constants
const PORT = process.env.PORT || 8080;
const HOST = '0.0.0.0';

const CLIENT_BUILD_PATH = path.join(__dirname, '../../300meter.ch/build');

// App
const app = express();

// Static files
app.use(express.static(CLIENT_BUILD_PATH));

//ssh

var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);

// All remaining requests return the React app, so it can handle routing.
app.get('*', function(request, response) {
  response.sendFile(path.join(CLIENT_BUILD_PATH, 'index.html'));
});

httpServer.listen(PORT, HOST);
httpsServer.listen(8443, HOST);

如果有人可以帮助我,那就太棒了。谢谢!

1 个答案:

答案 0 :(得分:0)

指定https://example.com时,客户端连接到端口443.您没有在端口443上运行SSL服务器。您的服务器正在端口8443上运行。

您需要在网址中指定https://example.com:8443/