ssl Apache2 Node Express无法验证第一个证书

bfnvny8b  于 7个月前  发布在  Apache
关注(0)|答案(1)|浏览(81)

我正在尝试做的是使用Node Express和Swagger创建一个API端点。我将部署该项目的服务器是Ubuntu。
在我在服务器上设置节点项目后,安装Apache 2并使用SSL证书和密钥设置HTTPS,访问网站工作正常。
但是,每当我尝试从本地向服务器发送API请求时,它都会返回一个错误,并显示“无法验证第一个证书”消息。

我拥有的证书和密钥文件是:

  1. CA_GLOBALSIGN_ROOT_CA.crt
  2. File_Wildcard.servername.com.crt
  3. ChainFile_ChainBundle.crt
  4. KeyFile_Wildcard.servername.com_crt.key
  5. complete_chain. crt(这是我通过组合(1).(2)和(3)文件创建的)。

.conf文件:

<VirtualHost *:80>
    ServerName servername.com
    Redirect permanent / https://servername.com/
</VirtualHost>
<VirtualHost *:443>
    ServerName servername.com

    SSLEngine on
    SSLProxyEngine on
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off
    SSLCertificateKeyFile /etc/apache2/ssl/KeyFile_Wildcard.servername.com_crt.key
    SSLProxyCACertificateFile /etc/apache2/ssl/CA_GLOBALSIGN_ROOT_CA.crt
    SSLCertificateFile /etc/apache2/ssl/complete_chain.crt

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / https://servername.com:3005/
    ProxyPassReverse / https://servername.com:3005/
</VirtualHost>

字符串

node项目中的app.js文件:

const express = require('express');
const orderRoutes = require('./routes/orderRoutes');
const swaggerUi = require('swagger-ui-express');
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerDef = require('./utils/swaggerDef');
const https = require('https');
const fs = require('fs');

const app = express();

app.use(express.json());

const options = {
  swaggerDefinition: swaggerDef,
  apis: ['./routes/*.js', './controllers/*.js'],
};

const swaggerSpec = swaggerJSDoc(options);

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.use('/api', orderRoutes);

const PORT = process.env.PORT || 3005;

const privateKey = fs.readFileSync('/etc/apache2/ssl/KeyFile_Wildcard.servername_crt.key');
const certificate = fs.readFileSync('/etc/apache2/ssl/complete_chain.crt');

const credentials = {
        key: privateKey,
        cert: certificate
}

const httpsServer = https.createServer(credentials, app);

httpsServer.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
});

module.exports = app;


我确实测试了openssl s_client -connect servername.com:443,但它也返回无法验证第一个证书。
我也试过使用nginx,但结果是一样的。
有人能帮我解决这个问题吗?
提前感谢!

lb3vh1jj

lb3vh1jj1#

链中包含什么?要设置服务器(无需客户端身份验证),您 * 只 * 需要链和密钥文件。
客户端期望的 * 第一个 * 证书是服务器的证书,然后是任何中间证书,然后是 * 可选 * 根证书。毕竟,客户端应该已经在其信任存储中拥有根证书。

相关问题