【发布时间】:2018-04-03 13:53:14
【问题描述】:
我做了一个简单的 nodejs web 应用程序并上传到 Azure,但它总是返回 403 禁止。
请求网址:https://wemwebconsole.azurewebsites.net/
请求方法:GET
状态码:403 禁止
我该如何解决这个问题?有什么问题吗?
文件树如所列。
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"
},
}
更新: 添加 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>
【问题讨论】:
-
是
process.env.PORT === 443?,或者如果你的服务器在负载均衡器后面,它是否转发443 =>process.env.PORT? -
改成“app.listen(process.env.PORT || 443)”,还是不行。
-
这行不通,我以为你控制了服务器,你没有将请求转发到你的应用程序。检查另一个问题。
-
还是不行
标签: javascript node.js azure azure-web-app-service