2017-01-15 122 views
0

當我嘗試導航到Azure網站時,出現403錯誤代碼,我收到以下錯誤。在Azure Web服務上部署節點JS應用程序

您沒有權限查看此目錄或頁面。

我已經創建了下面列出的正確的種子應用文件(我相信),並且很困惑爲什麼我仍然遇到這個錯誤。我沒有在應用程序日誌中看到任何可疑內容。

日誌:

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 [email protected] 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> 

回答

2

你的web.config告訴IIS使用iisnode模塊server.js路徑,但是所有其他路徑,包括網站根本不會受此影響。

如果你希望你的節點應用到顯示在您的蔚藍網站的根,你需要明確地告訴IIS這個問題:

<?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> 
相關問題