我的站点www.exampartner.in运行在一个EC2实例上,它使用连接到我在bigrock.in上购买的域的NodeJS。为了使用SSL,我迁移到了CloudFlare,但是自从迁移到CloudFlare之后,我的站点就出现了问题。主要问题是在将https重定向设置为页面规则后,我在javascript、徽标和ham pic上遇到的无效重定向错误。然后,我禁用了它,并试图通过HTTP加载这些资源,但仍然失败。现在,我也禁用了SSL,该页面似乎正在工作。我附上了屏幕截图作为参考。请帮帮忙。谢谢。这是我的routes.js:
var express = require('express');
var router = express.Router();
var passport = require('passport');
router.get('/login', function (req, res, next) {
res.render('login', { message: req.flash('loginMessage'), user: req.user });
});
router.get('/', function (req, res) {
res.render('mainpage', { user: req.user });
});
router.get('/signup', function (req, res, next) {
res.render('signup', { message: req.flash('signupMessage'), user: req.user });
});
// process the login form
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/login', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
// app.post('/signup', do all our passport stuff here);
router.post('/signup', passport.authenticate('local-signup', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/signup', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
// =====================================
// PROFILE SECTION =====================
// =====================================
// we will want this protected so you have to be logged in to visit
// we will use route middleware to verify this (the isLoggedIn function)
router.get('/profile', isLoggedIn, function (req, res) {
res.render('profile', {
user: req.user // get the user out of session and pass to template
});
});
// =====================================
// LOGOUT ==============================
// =====================================
router.get('/logout', function (req, res) {
req.logout();
res.redirect('/');
});
// };
// route middleware to make sure a user is logged in
function isLoggedIn(req, res, next) {
// if user is authenticated in the session, carry on
if (req.isAuthenticated())
return next();
// if they aren't logged redirect them to the home page
res.redirect('/');
}
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/login', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
router.get('/bitsat', function (req, res) {
res.render('bitsat', { user: req.user });
})
router.get('/aieee', function (req, res) {
res.render('aieee', { user: req.user });
})
router.get('/ip', function (req, res) {
res.render('ip', { user: req.user });
})
router.get('/jeemain', function (req, res) {
res.render('jeemain', { user: req.user });
})
router.get('/jeeadvanced', function (req, res) {
res.render('jeeadvanced', { user: req.user });
})
router.get('/jeemain/:year', function (req, res) {
res.render(__dirname + '/views/jee_main/' + req.params.year, { user: req.user });
});
router.get('/jeemain/:year/:paper', function (req, res) {
var filename = req.params.paper.substr(0, 2) + 'April' + req.params.year
var mor = req.params.paper.indexOf('Morning')
var eve = req.params.paper.indexOf('Evening')
if (mor !== -1) {
filename = filename + req.params.paper.substr(mor, req.params.paper.length)
}
if (eve !== -1) {
filename = filename + req.params.paper.substr(eve, req.params.paper.length);
}
res.download(__dirname + '/downloads/jee_main/' + req.params.year + '/' + filename + '.pdf')
});
router.get('/bitsat/:op', function (req, res) {
res.render(__dirname + '/views/bitsat/' + req.params.op, { user: req.user });
});
router.get('/bitsat/:op/:year', function (req, res) {
res.download(__dirname + '/downloads/bitsat/' + req.params.op + '/' + req.params.year + '.pdf')
});
module.exports = router;
发布于 2018-12-13 04:59:30
编辑:为了使用Cloudflare的严格SSL,您需要在服务器上安装证书。让我们加密提供免费的SSL证书,每90天更新一次。如果这个过程看起来很困难,您可以使用零SSL,这使得从我们加密获得证书以及更新现有证书变得很容易。
您必须设置express来处理https请求/响应。Node.js应用程序需要ssl证书和密钥。
const express = require('express')
const fs = require('fs')
const https = require('https')
const app = express()
https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')
}, app)
.listen(process.env.PORT || 3000, function () {
console.log('"App Listening at port:" + port')
})
https://stackoverflow.com/questions/53745938
复制相似问题