Reputation: 177
I made a simple nodejs web app and upload to Azure,but it always returns 403 forbidden.
Request URL: https://wemwebconsole.azurewebsites.net/
Request Method: GET
Status Code: 403 Forbidden
How could I fix this issue? Is there anything wrong?
The files tree is as listed.
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1> <%= temp %></h1>
</body>
</html>
server.js
var express = require('express');
var app = express();
var path = require('path');
var ejs = require('ejs');
var serveIndex = function(req, res, next) {
next();
};
//app.use(express.static(path.join(__dirname, 'dist')));
serveIndex = function(req, res, next) {
function renderIndex() {
var data = {
hhh:'hahaha'
};
ejs.renderFile( path.resolve('dist/index.html'), data, 'utf8', function (err, str) {
if (err === null) {
res.status(200).end(str);
}
else {
next(err);
}
});
};
renderIndex()
}
app.get('*', serveIndex);
app.listen(process.env.PORT || 443);
package.json
{
"name": "app",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "",
"dev": "",
"start": "node server.js"
},
"dependencies": {
"ejs": "2.4.1",
"express": "~4.13.4"
},
}
Update: Adding web.config does not work:
<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>
Upvotes: 3
Views: 2300
Reputation: 9940
I tried your code and it throws the error temp is not defined
on my site.
It works fine if I change the data Object to the following:
var data = {
temp: 'hahaha'
};
Furthermore, you can follow the post here to enable logging of stdout and stderr to troubleshoot the Node.js app in Azure.
Upvotes: 0
Reputation: 177
<?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>
OK,the specific web.config is here.
Upvotes: 4
Reputation: 154
You could try to access kudu console to investigate the issue. 403 error could mean many things; either you don't have access to this site, the site is stopped or the quota is exceeded. For more information, you may refer this doc: https://github.com/projectkudu/kudu/wiki/Investigating-issues.
Also, you may try to enable diagnostic logs to check the exact error message and see if it helps: https://learn.microsoft.com/en-us/azure/app-service/web-sites-enable-diagnostic-log.
Upvotes: 0