azure 您没有权限查看此目录或页面

ssm49v7z  于 2023-08-07  发布在  其他
关注(0)|答案(7)|浏览(188)

我在Azure上创建了一个应用服务来部署Node.js应用(express)。我跟着文档用教程应用做了一个zip deploy,效果很好。
现在我需要部署我自己的应用程序。我用我自己的应用程序的详细信息更新了web.config文件--用app.js代替了index.js--将其打包并上传。上传过程报告一切顺利。
但是,当我点击URL时,我得到以下错误:You do not have permission to view this directory or page.
接下来呢?我如何调试它?

krcsximq

krcsximq1#

接下来呢?
我犯了和你一样的错误。你可以参考我的工作步骤。

  • 应用程序.js*
  1. var createError = require('http-errors');
  2. var express = require('express');
  3. var path = require('path');
  4. var cookieParser = require('cookie-parser');
  5. var logger = require('morgan');
  6. var indexRouter = require('./routes/index');
  7. var usersRouter = require('./routes/users');
  8. var app = express();
  9. // view engine setup
  10. app.set('views', path.join(__dirname, 'views'));
  11. app.set('view engine', 'jade');
  12. app.set('port', process.env.PORT || 5000);
  13. console.log("+++++++++++++++"+ app.get('port'));
  14. app.use(logger('dev'));
  15. app.use(express.json());
  16. app.use(express.urlencoded({ extended: false }));
  17. app.use(cookieParser());
  18. app.use(express.static(path.join(__dirname, 'public')));
  19. app.use('/', indexRouter);
  20. app.use('/users', usersRouter);
  21. // catch 404 and forward to error handler
  22. app.use(function(req, res, next) {
  23. next(createError(404));
  24. });
  25. // error handler
  26. app.use(function(err, req, res, next) {
  27. // set locals, only providing error in development
  28. res.locals.message = err.message;
  29. res.locals.error = req.app.get('env') === 'development' ? err : {};
  30. // render the error page
  31. res.status(err.status || 500);
  32. res.render('error');
  33. });
  34. module.exports = app;
  35. app.listen(app.get('port'), function(){
  36. console.log('Express server listening on port ' + app.get('port'));
  37. });

字符串

  • Web.配置 *
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. This configuration file is required if iisnode is used to run node processes behind
  4. IIS or IIS Express. For more information, visit:
  5. https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
  6. -->
  7. <configuration>
  8. <system.webServer>
  9. <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
  10. <webSocket enabled="false" />
  11. <handlers>
  12. <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
  13. <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
  14. </handlers>
  15. <rewrite>
  16. <rules>
  17. <!-- Do not interfere with requests for node-inspector debugging -->
  18. <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
  19. <match url="^app.js\/debug[\/]?" />
  20. </rule>
  21. <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
  22. <rule name="StaticContent">
  23. <action type="Rewrite" url="public{REQUEST_URI}"/>
  24. </rule>
  25. <!-- All other URLs are mapped to the node.js site entry point -->
  26. <rule name="DynamicContent">
  27. <conditions>
  28. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
  29. </conditions>
  30. <action type="Rewrite" url="app.js"/>
  31. </rule>
  32. </rules>
  33. </rewrite>
  34. <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
  35. <security>
  36. <requestFiltering>
  37. <hiddenSegments>
  38. <remove segment="bin"/>
  39. </hiddenSegments>
  40. </requestFiltering>
  41. </security>
  42. <!-- Make sure error responses are left untouched -->
  43. <httpErrors existingResponse="PassThrough" />
  44. <!--
  45. You can control how Node is hosted within IIS using the following options:
  46. * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
  47. * node_env: will be propagated to node as NODE_ENV environment variable
  48. * debuggingEnabled - controls whether the built-in debugger is enabled
  49. See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
  50. -->
  51. <iisnode watchedFiles="web.config;*.js"/>
  52. </system.webServer>
  53. </configuration>

  • 路由/索引.js*
  1. var express = require('express');
  2. var router = express.Router();
  3. /* GET home page. */
  4. router.get('/', function(req, res, next) {
  5. res.render('index', { title: 'Express' });
  6. });
  7. module.exports = router;

  • 访问结果:*

x1c 0d1x的数据
更详细的情况,请参考本例:Running Node.js on Azure Web App的数据。
如何调试此问题?
要启用调试,请按照以下步骤操作:
1)如果您的根文件夹(D:\home\site\wwwroot)不存在,请在其中创建文件iisnode.yml。
2)将以下行添加到其中。

  1. loggingEnabled: true
  2. logDirectory: iisnode


完成后,您可以在D:\home\site\wwwroot\iisnode中找到日志。
有任何问题,请告诉我。

展开查看全部
x6h2sr28

x6h2sr282#

此问题通常是由于缺少web.config而导致的。
对我有效的解决方案:
在Linux环境中部署Web应用程序。
最简单的方法是使用git进行部署。在git部署中,git会自动创建一个web.config文件。

bbuxkriu

bbuxkriu3#

我也遇到了这个问题,这是因为缺少web.config文件。确保通过执行Application Settings>SCM_DO_BUILD_DURING_DEPLOYMENT>true添加应用程序设置SCM_DO_BUILD_DURING_DEPLOYMENT

dgenwo3n

dgenwo3n4#

我在Azure应用服务中部署Node.js API时也遇到过这个问题。
在web应用>设置>配置中添加SCM_DO_BUILD_DURING_DEPLOYMENT键,并将值设置为True

svujldwt

svujldwt5#

你可以做的另一件事是手动部署,然后检查web.config在Azure上的外观。我也遇到了同样的问题,最后追踪到:首先是缺少web.config,然后是错误的web. config。我在手动部署并检查2个配置文件后发现了这个问题-来自Azure的正确配置文件,我正在使用的错误配置文件。
您可以使用此命令通过Azure CLI进行手动部署:
az webapp up --sku F1 --name [AppServiceName] --os-type Windows --resource-group [ResourceGroupName]

u59ebvdq

u59ebvdq6#

将web.config添加到nodejs应用程序的根目录中解决了这个问题。去修理
1.将https://github.com/projectkudu/kudu/wiki/Using-a-custom-web.config-for-Node-apps的内容粘贴到web.config中
1.将'server.js'替换为您的应用程序js文件。例如index.js或app.js重新部署应用程序

7jmck4yq

7jmck4yq7#

这个问题的答案在package.json文件中-在package.json中添加这一行

  1. "scripts": {
  2. "start": "node app.js"
  3. },

字符串
然后部署你的app。

相关问题