在Azure Web Services上部署Node JS应用程序 [英] Deploying Node JS application on Azure Web Services

查看:70
本文介绍了在Azure Web Services上部署Node JS应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试导航到我的Azure网站时,我收到以下错误,并显示403错误代码.

I am receiving the following error with a 403 error code when I try to navigate to my Azure website.

您无权查看此目录或页面.

You do not have permission to view this directory or page.

我已经创建了下面列出的正确的种子应用程序文件(我相信),并且困惑为什么我仍然遇到此错误.我在应用程序日志中看不到任何可疑的东西.

I've created the proper seed app files (I believe) listed below, and am confused why I am still running into this error. I don't see anything suspicious on the application logs.

日志:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling node.js deployment.
KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
Copying file: 'server.js'
The package.json file does not specify node.js engine version constraints.
The node.js application will run with the default node.js version 6.9.1.
Selected npm version 3.10.8
npm WARN test@1.0.0 No description
Finished successfully.

文件:

server.js:

var express = require('express');
var app = express();

var PORT = process.env.PORT || 1337;

app.get('/', function (req, res) {
  res.send('Hello World!!')
});

app.listen(PORT, function () {
  console.log('App listening on port ' + PORT);
});

package.json:

{
  ...,
  "scripts": {
    "start": "node server",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  ...
}

web.config:

<configuration>
  <system.webServer>
    <handlers>
      <!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
      <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>
</configuration>

推荐答案

您的web.config告诉IIS将 iisnode 模块用于 server.js 路径,但是其他所有路径包括网站根目录在内的路径都不会受到此影响.

Your web.config tells IIS to use iisnode module for server.js path, however all other paths including website root will not be affected by this.

如果希望在Azure网站根目录上可以使用节点应用程序,则需要明确告知IIS:

If you want your node application to be available on your azure website root, you need to explicitly tell IIS about this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
            <rules>
                <rule name="DynamicContent">
                    <match url="/*" />
                    <action type="Rewrite" url="server.js"/>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这篇关于在Azure Web Services上部署Node JS应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆