简体   繁体   English

如何从Azure中的Node.js应用程序获取标准?

[英]How to get standard out from a Node.js application in Azure?

We have a Node.js application with a pretty big codebase that we're trying to deploy to an Azure Web Site. 我们有一个具有很大代码库的Node.js应用程序,我们正尝试将其部署到Azure网站。 My problem is that when I deploy the app and try to access it, I just get a message saying "The page cannot be displayed because an internal server error has occurred". 我的问题是,当我部署应用程序并尝试访问它时,我仅收到一条消息,内容为“由于发生内部服务器错误而无法显示该页面”。

According to http://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-debug/ I should be able to configure some settings and have my standard out be logged to a file - well, it's not working. 根据http://azure.microsoft.com/zh-CN/documentation/articles/web-sites-nodejs-debug/的说明,我应该能够配置一些设置并将我的标准记录到文件中-嗯,这是不工作。 in /LogFiles I can see /git, /html, and /DetailedErrors, but none of these folders contain the stdout logs. 在/ LogFiles中,我可以看到/ git,/ html和/ DetailedErrors,但是这些文件夹都不包含标准输出日志。

I have deployed the app using Visual Studio. 我已经使用Visual Studio部署了该应用程序。 I created a blank Azure project, and manually added all the folders and files I need. 我创建了一个空白的Azure项目,并手动添加了所需的所有文件夹和文件。 I also created an iisnode.yml file that contains the following config: 我还创建了一个iisnode.yml文件,其中包含以下配置:

loggingEnabled: true
devErrorsEnabled: true
logDirectory: ./logs
debugHeaderEnabled: true

The last two lines I added later, the first ones are from the tutorial. 我稍后添加的最后两行,前几行来自本教程。 I also have a web.config file, the contents of which I haven't really touched. 我也有一个web.config文件,其内容尚未真正涉及。

I've attempted to configure the settings that are available in the Web Sites UI, but I haven't really been able to make any headway. 我试图配置网站UI中可用的设置,但实际上并没有取得任何进展。 I think currently they are pretty much default. 我认为目前它们几乎是默认值。

I'm sorry that I can't provide you with more information. 很抱歉无法为您提供更多信息。 I'm really kind of banging my head against the wall here, since all the tutorials I've found basically state that if I do this and that, everything should work. 我真的很想在这里撞墙,因为我发现的所有教程基本上都指出,如果我这样做,那一切都会正常进行。 The problem is, it doesn't. 问题是,事实并非如此。 Sad face. 悲伤的脸。

Edit: I should probably add that my server.js is in a folder called /NodeServer. 编辑:我可能应该添加我的server.js在一个名为/ NodeServer的文件夹中。 It's not in the root as Azure seems to presume. 它似乎不是Azure所假定的根源。

Edit2: I deployed a Hello World example and got it to work, but when I try to move the server.js file from the root I can't get it to work anymore. Edit2:我部署了一个Hello World示例并使它工作,但是当我尝试从根目录移动server.js文件时,我再也无法使其工作了。

I've added a tag to the web.config, so that the structure is basically 我在web.config中添加了一个标签,因此结构基本上是

configuration
  location path="NodeServer"
   system.webServer

I've also edited my package.json so that it says 我还编辑了package.json,使其显示为

"main":"NodeServer/server.js",
"scripts":{
   "start":"cd NodeServer && node server.js"
}

If the app is started successfully, you should be able to find the stdout at 如果应用程序成功启动,您应该可以在以下位置找到标准输出

D:\home\LogFiles\Application

in Azure Websites, without configuring anything. 在Azure网站中,无需进行任何配置。

But here it looks like an error related to incorrect/missing web.config. 但是在这里,它看起来像是与web.config错误/丢失有关的错误。 The node app may not get launched. 节点应用可能无法启动。 You can try: 你可以试试:

  1. Publishing your app using git to Azure Websites. 使用git将应用程序发布到Azure网站。
  2. Or if you are familiar with IIS and iisnode, make sure your app works locally with IIS and iisnode. 或者,如果您熟悉IIS和iisnode,请确保您的应用程序在IIS和iisnode上本地运行。 See http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html 参见http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html
  3. Or try publishing an "hello world" node.js app to Azure Websites, take the generated web.config and modify it for your app. 或尝试将“ hello world” node.js应用程序发布到Azure网站,获取生成的web.config并为您的应用程序对其进行修改。

Edit: When you change the location of server.js, you have to change web.config too. 编辑:当您更改server.js的位置时,您也必须更改web.config。 The change in web.config is not correct. web.config中的更改不正确。 And package.json is only used as hints to generate web.config during git deployment. 而package.json仅用作在git部署期间生成web.config的提示。 To get your "hello world" to work, you can either 要使“ hello world”发挥作用,您可以选择

  1. In your web.config, replace all "server.js" with "NodeServer/server.js". 在您的web.config中,将所有“ server.js”替换为“ NodeServer / server.js”。
  2. Or deploy the modified app using git. 或使用git部署修改后的应用程序。 Make sure it does not contain the wrong web.config. 确保它不包含错误的web.config。

Then you can try to get your larger app to work. 然后,您可以尝试使用更大的应用程序。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM