【发布时间】:2021-09-10 14:57:35
【问题描述】:
我目前正在开发一个应用程序。在我的本地机器上一切正常,但在我的实时服务器上,我遇到了一个我无法在网站的 http 和 https 版本之间解决的问题。有谁知道为什么我在这两个域的显示上有所不同?
我已经在服务器上安装了 SSL 证书,但几天来一直试图弄清楚这里发生了什么。
这是我的 www 文件的样子:
#!/usr/bin/env node
/**
* Module dependencies.
*/
const app = require('../app')
const debug = require('debug')('maksemus.tech:server')
const spdy = require('spdy')
const fs = require('fs')
const http = require('http')
const https = require('https')
const privateKey = fs.readFileSync('./mkcert/maksemus_tech_key.key')
const certificate = fs.readFileSync('./mkcert/maksemus_tech_cert.crt')
const options = {
// Private key
key: privateKey,
// Fullchain file or cert file (prefer the former)
cert: certificate,
}
/**
* Get port from environment and store in Express.
*/
const httpPort = normalizePort(process.env.HTTPPORT)
const httpsPort = normalizePort(process.env.HTTPSPORT)
/**
* Create HTTP/HTTPS/SPDY server.
*/
httpServer = http.createServer(app)
httpServer.listen(httpPort)
httpServer.on('error', onError)
httpServer.on('listening', onListening)
httpsServer = spdy.createServer(options, app)
httpsServer.listen(httpsPort)
httpsServer.on('error', onError)
httpsServer.on('listening', onListening)
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind1 = typeof httpPort === 'string' ? 'Pipe ' + httpPort : 'Port ' + httpPort
var bind2 = typeof httpsPort === 'string' ? 'Pipe ' + httpsPort : 'Port ' + httpsPort
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind1 + ' requires elevated privileges')
console.error(bind2 + ' requires elevated privileges')
process.exit(1)
break
case 'EADDRINUSE':
console.error(bind1 + ' is already in use')
console.error(bind2 + ' is already in use')
process.exit(1)
break
default:
throw error
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr1 = httpServer.address()
console.log(addr1)
var addr2 = httpsServer.address()
console.log(addr2)
var bind1 = typeof addr1 === 'string' ? 'pipe ' + addr1 : 'port ' + addr1.port
debug('HTTP Server Listening on ' + bind1)
var bind2 = typeof addr2 === 'string' ? 'pipe ' + addr2 : 'port ' + addr2.port
debug('HTTPS Server Listening on ' + bind2)
}```
【问题讨论】:
标签: node.js apache express http https