0
我使用apache服務器根據特定域的請求重定向到NodeJS服務器。但是,當我向js代碼(服務器代碼)添加一些功能時,它會顯示類似「未定義」的內容,即使我嘗試重新啓動apache服務器,並殺死了所有與節點相關的進程。如何在通過Apache託管nodejs應用程序時重新啓動nodejs服務器以應用更改
現在該怎麼辦?
我使用apache服務器根據特定域的請求重定向到NodeJS服務器。但是,當我向js代碼(服務器代碼)添加一些功能時,它會顯示類似「未定義」的內容,即使我嘗試重新啓動apache服務器,並殺死了所有與節點相關的進程。如何在通過Apache託管nodejs應用程序時重新啓動nodejs服務器以應用更改
現在該怎麼辦?
用forever運行您的節點服務器。還有其他的監控庫。
這個想法是,當文件改變(可以是白名單),應用程序將重新啓動。如果通過Apache傳遞流量,則需要此操作,因爲重新啓動Apache將不會重新啓動節點應用程序,該應用程序需要重新啓動以讀取更改。
我用這樣的腳本來啓動我的應用程序forever
,我在開發過程中使用它node start.js
或在生產中使用一些環境變量來配置我的節點ENV和「引導」服務,以便它運行的機器上開始(我使用upstart
)。
/*jslint node: true */
"use strict";
/**
* File to start using forever, logs crashes, restarts on file changes, etc.
*/
var cmd = (process.env.DBG ? "node --debug" : "node");
var forever = require('forever'),
//exec = require('child_process').exec,
child = new(forever.Monitor)('node', {
'silent': false,
'pidFile': 'pids/forever-app.pid',
'watch': true,
'command': cmd,
'args': ['app.js' ],
//"max" : 10,
'watchDirectory': './', // Top-level directory to watch from.
'watchIgnoreDotFiles': true, // whether to ignore dot files
'watchIgnorePatterns': [ 'log/*', 'node_modules/*', 'pids/*',
'dbscripts/*', 'test/*',
'curlcookies',
'.svn/*', ], // array of glob patterns to ignore, merged with contents of watchDirectory + '/.foreverignore' file
'logFile': 'log/forever.log', // Path to log output from forever process (when daemonized)
//'outFile': 'logs/ijoin-forever.out', // Path to log output from child stdout
'errFile': 'log/forever.err'
});
child.on("exit", function() {
console.log('app.js has exited!');
});
child.on("restart", function() {
console.log('app.js has restarted.');
});
child.on('watch:restart', function(info) {
console.error('Restaring script because ' + info.file + ' changed');
});
child.start();
forever.startServer(child);
process.on('SIGINT', function() {
console.log("\nGracefully shutting down \'node forever\' from SIGINT (Ctrl-C)");
// some other closing procedures go here
process.exit();
});
process.on('exit', function() {
console.log('About to exit \'node forever\' process.');
});
process.on('uncaughtException', function(err) {
console.log('Caught exception in \'node forever\': ' + err);
});