【发布时间】:2017-08-03 08:56:07
【问题描述】:
我正在尝试为我的 ExpressJS 应用程序配置 https 连接。 Express 服务器在 localhost:8080 和安全服务器 localhost:8443 运行。
这里是https相关的server.js代码:
var app = express();
var https = require('https');
const options = {
cert: fs.readFileSync('/etc/letsencrypt/live/fire.mydomain.me/fullchain.pem'),
key: fs.readFileSync('/etc/letsencrypt/live/fire.mydomain.me/privkey.pem')
};
app.listen(8080, console.log("Server running"));
https.createServer(options, app).listen(8443, console.log("Secure server running on port 8443"));
这是我的 Nginx 配置:
server {
listen 80;
listen [::]:80;
server_name fire.mydomain.me;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 443;
listen [::]:443;
server_name fire.mydomain.me;
location / {
proxy_pass https://localhost:8443;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
我做了什么:
- 使用 Letsencrypt certonly 工具为域 fire.mydomain.me 生成 SSL 证书。
- 配置 nginx。
- 配置 server.js 节点应用程序。
- 为 Ufw 中的 443 端口添加 TCP 规则。
我试过了
注释 server.js 中的非 ssl 服务器行以强制连接通过 ssl 配置:当我尝试转到 fire.mydomain.me:443 但不转到“https: // fire.mydomain.me"。在这两种情况下,都没有 SSL。尝试访问 https://fire.mydomain.me 在 Google Chrome 中生成此消息“此网站不提供安全连接”。
我首先按照本教程设置了我的 ssl 节点配置: https://medium.com/@yash.kulshrestha/using-lets-encrypt-with-express-e069c7abe625#.93jgjlgsc
【问题讨论】:
标签: javascript node.js ssl nginx https