带有虚拟主机和greenlock-express的NodeJS子域

时间:2018-09-09 04:20:21

标签: node.js express https vhosts greenlock

我是Node的新手,我希望我的网站dacio.app使用vhost处理大学项目的子域。

但是,由于需要.app域,因此我需要确保它的安全,因此我正在使用greenlock-express对其进行自动化。

  

别在前面,哟! TLS SNI'giphy.dacio.app'与“主机:   potato.dacio.app'

我尝试在vhost example中使用repo,但看起来server-static不支持express应用。


有关如何使其正常工作的任何提示?我不断听到反向代理的消息,但是我不确定是否值得付出努力,因为我什至不知道它是否会起作用-会有所帮助吗?

server.js

#!/usr/bin/env node
'use strict';

// DEPENDENCIES
const express = require('express');
const vhost   = require('vhost');
const path    = require('path');
const glx     = require('greenlock-express');

// MIDDLEWARE
const app = express();
const giphyApp = require('../giphy-search');
const potatoesApp = require('../rotten-potatoes');
const portfolioApp = require('../dacio.app');

// ROUTES
app.use(vhost('giphy.dacio.app', giphyApp));
app.use(vhost('potatoes.dacio.app', potatoesApp));
app.use(portfolioApp);

// GREENLOCK for HTTPS
glx.create({
    version: 'draft-11',
    server: 'https://acme-v02.api.letsencrypt.org/directory',
    email: 'dacioromero@gmail.com',
    agreeTos: true,
    approveDomains: [ 'dacio.app', 'giphy.dacio.app', 'potatoes.dacio.app' ],
    configDir: '~/.config/acme/',
    app: app,
    communityMember: false
}).listen(80, 443);

1 个答案:

答案 0 :(得分:0)

我已改用redbird,它似乎可以完成我希望做的所有事情。

const path = require('path')

const proxy = require('redbird')({
    port: 80,
    letsencrypt: {
        path: path.join(__dirname, '/certs'),
        port: 9999
    },
    ssl: {
        http2: true,
        port: 443
    }
});

proxy.register('dacio.app', 'http://localhost:8080', {
    ssl: {
        letsencrypt: {
            email: 'dacioromero@gmail.com',
            production: true,
        }
    }
});

proxy.register('giphy.dacio.app', 'http://localhost:8081', {
    ssl: {
        letsencrypt: {
            email: 'dacioromero@gmail.com',
            production: true
        }
    }
})

proxy.register('potatoes.dacio.app', 'http://localhost:8082', {
    ssl: {
        letsencrypt: {
            email: 'dacioromero@gmail.com',
            production: true
        }
    }
});