我想先说这是我第一次在服务器上放置应用程序。我按照教程,并能够创建一个hello world应用程序,当我通过私有IP访问服务器时,我得到一个回复说“你好世界”
Hello world app
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Ricky\n');
}).listen(3000, 'localhost');
console.log('Server running at http://localhost:3000/');
这个应用程序是通过命令“pm2 start hello.js”运行的,但是当我尝试用我的实际应用程序重复该过程时,我得到500错误
我的应用
var app = require('../app');
var debug = require('debug')('nodetest1:server');
var http = require('http');
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
var server = http.createServer(app);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
这是我的Nginx配置文件
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
server_name _;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
我从哪里开始解决此问题? 500错误太宽泛而无法理解,如何访问错误日志以查看导致500的错误?