Tag: httpredirect

HTTP在不同的端口redirect到HTTPS

我正在尝试将每个http请求redirect到https服务器。 如果https服务器的端口是443, 这工作正常 。但是,如果我尝试redirect到不同的端口,它不会发生。 这是我的代码: http.createServer(function(req,res){ var host = req.headers['host'], url = req.url; res.writeHead(301, {"Location": "https://" + host + ":"+SERVER.SPORT + url}) res.end() }).listen(SERVER.PORT) https.createServer(SERVER.HTTPS_OPTIONS,app).listen(SERVER.SPORT)