我成功地侦听了端口443,可以通过https访问服务器,但是我不能使用http访问它。
var fs = require('fs')
options = {
ca : fs.readFileSync('./ssl/site.com.pem'),
key: fs.readFileSync('./ssl/site.com.key'),
cert: fs.readFileSync('./ssl/site_com.crt')
}
var app = require('express.io')
app.https(options).io()
....
app.listen(443);我尝试过使用http和https模块:
app.http().io();
http.createServer(app).listen(80);
https.createServer(options, app).listen(443);但这一次,socket.io在浏览器中提供了404。我怎么才能解决这个问题?我需要使用Express.Io的socket连接,因为应用程序是基于它的。
发布于 2014-11-05 19:22:31
您应该将http重定向到https。
var express = require('express'),
app = express(),
httpapp = express();
//........................
var credentials = {key: privateKey, cert: certificate, ca: ca};
var httpsServer = https.createServer(credentials, app);
var httpServer = http.createServer(httpapp);
httpsServer.listen(443);
httpServer.listen(80);
httpapp.route('*').get(function(req,res){
res.redirect('https://yourdomain.com'+req.url)
});发布于 2014-11-16 23:07:41
几天前也有同样的问题,这个GitHub问题起了作用:https://github.com/techpines/express.io/issues/17#issuecomment-26191447
您的代码在正确的方向上,它只是需要一些更改。下面的代码是您提供的代码片段的稍微修改的版本。
var fs = require('fs'),
express = require('express.io');
options = {
ca : fs.readFileSync('./ssl/site.com.pem'),
key: fs.readFileSync('./ssl/site.com.key'),
cert: fs.readFileSync('./ssl/site_com.crt')
};
var app = express();
app.https(options).io();
var httpServer = require('http').createServer(app);
// ...
app.listen(443);
express.io.listen(httpServer);
httpServer.listen(80, function() { }, function() { });https://stackoverflow.com/questions/26762310
复制相似问题