小编Gui*_*ume的帖子

为Express和Nginx配置HTTPS

我正在尝试配置我的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"));
Run Code Online (Sandbox Code Playgroud)

这是我的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'; …
Run Code Online (Sandbox Code Playgroud)

javascript ssl https nginx node.js

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

https ×1

javascript ×1

nginx ×1

node.js ×1

ssl ×1