简体   繁体   English

将Express Node.js项目部署到Azure 500服务器错误

[英]Deploying express node.js project to azure 500 server error

Seem to have tried every available solution even though some claim that Azure have fixed this issue internally, but I cannot get it to work, production deployment gives me a 500 error every time. 似乎已经尝试了所有可用的解决方案,即使有些人声称Azure已在内部修复了此问题,但我无法使其正常工作,生产部署每次都会给我500错误。 Deploying locally works. 在本地部署工作。 Here's my app.js which is basically "out of the box" with express 4.12.2 这是我的app.js,基本上是Express 4.12.2的“开箱即用”

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.set('port', process.env.PORT || 1337);
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});


module.exports = app;

app.listen(app.get('port'), function(){
           console.log('Express server listening on port ' + app.get('port'));
           });

I suspect you might be getting this error in the logs. 我怀疑您可能在日志中收到此错误。

Error: ENOENT, open 'D:\\home\\site\\wwwroot\\bin\\views\\layouts\\main.handlebars' at Error (native)

Enable the error logs 启用错误日志

Note the path to the views folder. 请注意views文件夹的路径。

You could try remove the www file. 您可以尝试删除www文件。 Check the last couple of paragraphs in the Express docs on how. 查看Express文档中的最后两段,了解如何操作。

Also I found that adding app.use(express.static('public')); 我也发现添加app.use(express.static('public')); is needed if you have resources like images and fonts – it would fail silently otherwise. 如果您拥有图像和字体之类的资源,则需要使用它-否则,它将无提示地失败。

Make sure that your entry point is in the root folder. 确保您的入口点在根文件夹中。

In my case, my entry point was './bin/www', I had to manually move this file to root and update the and sections in the Web.config to get it working. 在我的情况下,我的入口点是“ ./bin/www”,我必须手动将此文件移至根目录并更新Web.config中的和部分,以使其正常工作。

Deploy again after making these changes. 进行这些更改后,请再次部署。

there were a couple solutions provided in the following question 在以下问题中提供了几种解决方案

Azure NodeJS Error: ENOENT, open 'D:\\home\\site\\wwwroot\\bin\\views\\' Azure NodeJS错误:ENOENT,打开“ D:\\ home \\ site \\ wwwroot \\ bin \\ views \\”

for now I simply used the following near the top of app.js process.chdir(__dirname); 现在,我只是在app.js process.chdir(__ dirname);顶部附近使用了以下内容:

I know it is very tricky to handle such scenarios. 我知道处理这种情况非常棘手。

  1. Try to understand/google what versions of nodejs azure portal supports. 尝试了解/ google nodejs azure门户支持哪些版本。 It supports only specific versions. 它仅支持特定版本。 Note those versions and try to use any version you need or try using latest version only from that list. 记下这些版本,并尝试使用所需的任何版本,或者仅尝试使用该列表中的最新版本。
  2. In azure portal -> go to your app service -> you should see console in appservice details -> Type node -v. 在azure门户中->转到您的应用程序服务->您应该在应用程序服务详细信息中看到控制台->输入节点-v。
  3. This should give you node version may be like 0.10.4 or so. 这应该给您的节点版本可能像0.10.4左右。 This may be the main main and main culprit. 这可能是主要的罪魁祸首。
  4. Go to your app settings under configuration for your app service. 在您的应用程序服务的配置下转到您的应用程序设置。 Add node version there like WEBSITE_NODE_DEFAULT_VERSION as your node version ex: 8.9.4 在其中添加节点版本,例如WEBSITE_NODE_DEFAULT_VERSION作为您的节点版本,例如:8.9.4
  5. Go to your package.json and add node version same as you used in azure portal appsettings. 转到package.json并添加与Azure门户应用程序设置中使用的节点版本相同的节点版本。 ex: "engines": { "node": "8.9.4" } 例如:“ engines”:{“ node”:“ 8.9.4”}
  6. Restart app service -> check console -> node -v. 重新启动应用程序服务->检查控制台->节点-v。 if this shows same version then deploy application and it should work with out any issues. 如果显示相同的版本,则部署应用程序,并且应该不会出现任何问题。

How to check real errors instead of 500 如何检查实际错误而不是500

  1. In azure portal for your app service enable diagnostic logs 在您的应用服务的Azure门户中启用诊断日志
  2. Select log stream 选择日志流
  3. Refresh your site. 刷新您的网站。 Now you should see real error message in log stream. 现在,您应该在日志流中看到真正的错误消息。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 内部服务器错误500,在Azure中托管来自Visual Studio 2017的Node.js Express 4应用程序模板 - Internal server error 500, hosting Node.js Express 4 application template from Visual Studio 2017 in Azure 向 node.js express 服务器发送消息时出现错误 500 - Error 500 when sending a message to node.js express server 500内部服务器在尝试访问Microsoft Azure node.js / express Web应用程序上的CSV文件时出错? - 500 Internal Server Error when trying to access CSV file on Microsoft Azure node.js/express web app? 将 Node.JS express API App 部署到 Azure App Service - Deploying Node.JS express API App to Azure App Service Node JS Express 500服务器错误 - Node js express 500 server error 使用 Node.js 和 express.js 实现护照-facebook-token 时出现 500 内部服务器错误 - 500 Internal Server Error in passport-facebook-token implementation using Node.js and express.js 在node.js Express服务器上部署angular Universal - deploying angular universal on node.js express server 内部500错误-Node.js-快速会话 - Internal 500 Error - Node.js - express-session 在Azure上部署Node.js + socket.io后端/服务器 - Deploying node.js + socket.io backend/server on azure 如何解决错误 HRESULT: 0x6d HTTP 500 substatus 1013 when Deployed in Azure with Node.js Express and IISnode? - How to solve error HRESULT: 0x6d HTTP 500 substatus 1013 when Deployed in Azure with Node.js Express and IISnode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM