我使用apache服务器根据特定域的请求重定向到NodeJS服务器。但是当我在js代码(服务器代码)中添加一些函数时,它显示类似于“未定义”之类的内容,甚至我试图重启apache服务器,并终止了所有与节点相关的进程。
我现在该怎么做?
发布于 2015-01-12 23:32:14
使用forever运行您的节点服务器。还有其他的监控库。
其想法是,当文件发生变化(可以被列入白名单)时,应用程序将重新启动。如果通过Apache传递流量,则需要此选项,因为重启Apache不会重启Node应用程序,而Node应用程序需要重启才能读取您的更改。
我使用这样的脚本在forever中启动我的应用程序,在使用node start.js进行开发期间或在生产环境中使用它,并使用一些环境变量来配置我的Node,以及一个“启动时”服务,以便它在机器启动时运行(我使用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 );
} );https://stackoverflow.com/questions/27898721
复制相似问题