【发布时间】:2021-05-21 03:50:49
【问题描述】:
首先 - 我对这些东西真的很陌生。我想为我正在开发的 webapp 获取 ssl 证书。我期待任何建议。 使用 Ubuntu 20.04
结构如下:
-
我正在使用 Nginx 在端口 80 上提供我的前端,以侦听我指定的 server_name(服务器的域名)。
-
node.js 后端使用 pm2 在服务器 IP 地址的 60702 端口上运行。
我的尝试:
我尝试从letsencrypt获取证书并为我的前端做好准备,就像这里描述的digitalocean:
server{
# SSL configuration
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
# Path to certificates and configuration
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
...
在 vue 配置中,我将 https 设置为 true:
module.exports = {
baseUrl: './',
devServer: {
port: 8080,
https: true,
disableHostCheck: true
}
};
问题出在我的后端。我试过了:
https.createServer({
key: fs.readFileSync('certs/selfsigned.key', 'utf8'),
cert: fs.readFileSync('certs/selfsigned.crt', 'utf8'),
//key: fs.readFileSync('certs/key.pem', 'utf8'),
//cert: fs.readFileSync('certs/cert.pem', 'utf8'),
rejectUnauthorized: false
}, app)
.listen(nconf.get('port'), function() {
console.log(`App listening on port ${nconf.get('port')}! Go to https://MY_IP:${nconf.get('port')}/`)
});
但我在这里读到:letsencrypt on IP addresses,letsencrypt 不提供 IP 地址证书。
那么我怎样才能为我的申请获得证书呢? 我该怎么做呢?
我需要将证书链接到前端和后端吗?
【问题讨论】: