我有一個正在開發的應用程式。在我的本地機器上一切正常,但在我的實時服務器上,我在網站的 http 和 https 版本之間遇到了一個我無法解決的問題。有誰知道為什么我在這兩個域名的顯示上會有差異?
我已經在服務器上安裝了SSL證書,但為了弄清楚這里發生的事情,我已經卡了好幾天了。
下面是我的www檔案的樣子:
。
/**。
* 模塊的依賴性。
*/
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('htps')
const privateKey = fs.readFileSync(' ./mkcert/maksemus_tech_key.key')
const certificate = fs.readFileSync(' ./mkcert/maksemus_tech_cert.crt')
const options = {
//私鑰
key: privateKey,
// Fullchain file or cert file (preferred the former)
cert: 證書。
}
/***:證書。
*從環境中獲取埠并存盤在Express中。
*/
const httpPort = normalizePort(process.env.HTTPPORT)
const httpsPort = normalizePort(process.env.HTTPSPORT)
/**。
*創建HTTP/HTTPS/SPDY服務器。
*/
httpServer = http.createServer(app)
httpServer.listen(httpPort)
httpServer.on('error'/span>, one rror)
httpServer.on('listening', onListening)
httpsServer = spdy.createServer(options, app)
httpsServer.listen(httpsPort)
httpsServer.on('error'/span>, one rror)
httpsServer.on('listening', onListening)
/***。
* 將一個埠規范化為數字、字串或false。
*/
function normalizePort(val) {
var port = parseInt(val, 10)。
if (isNaN(埠)) {
//命名管道。
return val;
}
if (port >= 0) {
//port number
return port。
}
return false;
}
/***。
* HTTP服務器 "錯誤 "事件的事件監聽器。
*/
function onError(error) {
if (error.syscall !=='listen') {
throw 錯誤。
}
var bind1 = typeof httpPort === 'string' ? 'Pipe ' httpPort : 'Port ' httpPort !
var bind2 = typeof httpsPort === 'string'/span> ? 'Pipe ' httpsPort : 'Port ' httpsPort ?
//用友好資訊處理特定的監聽錯誤。
switch (error.code) {
case 'EACCES'/span>:
console.error(bind1 ' requires elevated privileges')
console.error(bind2 ' requires elevated privileges')
process.exit(1)
break(1)
case 'EADDRINUSE'/span>:
console.error(bind1 ' is already in use')
console.error(bind2 '已在使用中')
process.exit(1)
break(1)
default:
throw error
}
}
/****
* HTTP服務器 "監聽 "事件的事件監聽器。
*/
function onListening() {
var addr1 = httpServer.address()
console.log(addr1)
var addr2 = httpsServer.address()
console.log(addr2)
var bind1 = typeof addr1 === 'string'/span> ? 'pipe ' addr1 : 'port ' addr1.port ?
debug('HTTP Server Listening on ' bind1)
var bind2 = typeof addr2 === 'string'/span> ? 'pipe ' addr2 : 'port ' addr2.port ?
debug('HTTPS Server Listening on ' bind2)
}````。
uj5u.com熱心網友回復:
經過大量的除錯,我找到了導致這個問題的原因。這是由Phusion Passengers的應用程式實體化引起的。
它在初始化應用程式時簡單地使用了兩個不同的路徑。一個用于 http,一個用于 https。
它為 http 配置使用的標準路徑是:
不知道為什么,當你在cpanel中注冊你的應用程式時,Phusion Passenger不會自動為SSL創建正確的路徑,這意味著它無法找到https應用程式配置的路徑。
我不得不手動創建檔案夾,然后從上述路徑復制組態檔到其中。它看起來像這樣: 如果你更新一個組態檔,你需要更新另一個,因為它們應該是相同的。
[cpanel 檔案][1]中的命令列對我不起作用,因為這些檔案夾并不存在,而且在注冊應用程式時也沒有自動創建。
我所指的上述檔案中的命令列是: 無論如何,一旦你創建了這兩個路徑,你需要重建apache的http組態檔,并重新啟動apache。
希望這能為其他人省去這場噩夢。
標籤:/etc/data.htm。
/etc/apache2/conf.d/userdata/std/2_4/YOUR_USERNAME/YOUR_DOMAIN/YOUR_APP_NAME.conf/etc/documents.htm
/etc/apache2/conf.d/userdata/ssl/2_4/YOUR_USERNAME/YOUR_DOMAIN/YOUR_APP_NAME.confcp -a /etc/apache2/conf.d/userdata/std/2_4/username/example.com/application-name。 conf /etc/apache2/conf.d/userdata/ssl/2_4/username/example。 com/application-name.conf。
/usr/local/panel/scripts/rebuildhttpdconf
/usr/local/cpanel/scripts/restartsrv_httpd
