【Azure 应用服务】Azure Mobile App (NodeJS) 的服务端部署在App Service for Windows中出现404 Not Found -- The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
问题描述
使用NodeJS的后端应用,开发一个Mobile App的服务端,手机端通过REST API来访问获取后端数据。在本地编译好后,通过npm start启动项目,访问效果如下:
但是,当把项目文件通过FTP,或者直接VS Code 部署到App Service for windows后,访问首页并不是mobile app的页面,而是默认的App Service页面,访问项目里面的API也是404错误?
问题解决
从访问默认URL和测试API为404的效果来看,这是NodeJS项目并没有启动。因为是App Service For Windows环境,非ASP.NET的项目都需要通过IIS启用对于的进程文件来执行代码。如NodeJS项目则会启动一个 node.exe 用于执行 js 文件。
所以第一步是进入到App Service的高级工具 (Kudu)站点中,查看以下图片中的两点:
1: node.exe 进程是否存在
2: node.exe 进程中所加载的js文件是否是正确的启动文件
如果缺少了Web.config文件,则以下面的内容来创建它:
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- This configuration file is required if iisnode is used to run node processes behind
- IIS or IIS Express. For more information, visit:
- https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
- -->
- <configuration>
- <system.webServer>
- <!-- 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 -->
- <webSocket enabled="false" />
- <handlers>
- <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
- <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
- </handlers>
- <rewrite>
- <rules>
- <!-- Do not interfere with requests for node-inspector debugging -->
- <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
- <match url="^app.js\/debug[\/]?" />
- </rule>
- <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
- <rule name="StaticContent">
- <action type="Rewrite" url="public{REQUEST_URI}"/>
- </rule>
- <!-- All other URLs are mapped to the node.js site entry point -->
- <rule name="DynamicContent">
- <conditions>
- <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
- </conditions>
- <action type="Rewrite" url="app.js"/>
- </rule>
- </rules>
- </rewrite>
- <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
- <security>
- <requestFiltering>
- <hiddenSegments>
- <remove segment="bin"/>
- </hiddenSegments>
- </requestFiltering>
- </security>
- <!-- Make sure error responses are left untouched -->
- <httpErrors existingResponse="PassThrough" />
- <!--
- You can control how Node is hosted within IIS using the following options:
- * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
- * node_env: will be propagated to node as NODE_ENV environment variable
- * debuggingEnabled - controls whether the built-in debugger is enabled
- See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
- -->
- <!--<iisnode watchedFiles="web.config;*.js"/>-->
- </system.webServer>
- </configuration>
PS: handlers 和 rewrite 部分是必须的,其中 app.js 的名称可以根据实际项目中的启动文件而修改。
当web.config添加后,问题解决,再次访问效果为:
附录一:如果是遇见的其他错误,如 Module 缺少,则可以在 Logfiles中的 Application 文件夹中的 logging-errors.txt 中查看详细错误,如:
- Mon Jan 24 2022 10:59:28 GMT+0000 (Greenwich Mean Time): Application has thrown an uncaught exception and is terminated:
- Error: Cannot find module 'express'
- Require stack:
- - D:\home\site\wwwroot\index.js
- - D:\Program Files (x86)\iisnode\interceptor.js
- at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
- at Function.Module._load (internal/modules/cjs/loader.js:667:27)
- at Module.require (internal/modules/cjs/loader.js:887:19)
- at require (internal/modules/cjs/helpers.js:74:18)
- at Object.<anonymous> (D:\home\site\wwwroot\index.js:1:17)
- at Module._compile (internal/modules/cjs/loader.js:999:30)
- at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
- at Module.load (internal/modules/cjs/loader.js:863:32)
- at Function.Module._load (internal/modules/cjs/loader.js:708:14)
- at Module.require (internal/modules/cjs/loader.js:887:19)
- Mon Jan 24 2022 11:09:37 GMT+0000 (Greenwich Mean Time): Application has thrown an uncaught exception and is terminated:
- Error: Cannot find module 'depd'
- Require stack:
- - D:\home\site\wwwroot\node_modules\body-parser\index.js
- - D:\home\site\wwwroot\node_modules\express\lib\express.js
- - D:\home\site\wwwroot\node_modules\express\index.js
- - D:\home\site\wwwroot\index.js
- - D:\Program Files (x86)\iisnode\interceptor.js
- at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
- at Function.Module._load (internal/modules/cjs/loader.js:667:27)
- at Module.require (internal/modules/cjs/loader.js:887:19)
- at require (internal/modules/cjs/helpers.js:74:18)
- at Object.<anonymous> (D:\home\site\wwwroot\node_modules\body-parser\index.js:14:17)
- at Module._compile (internal/modules/cjs/loader.js:999:30)
- at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
- at Module.load (internal/modules/cjs/loader.js:863:32)
- at Function.Module._load (internal/modules/cjs/loader.js:708:14)
- at Module.require (internal/modules/cjs/loader.js:887:19)
- Mon Jan 24 2022 11:10:24 GMT+0000 (Greenwich Mean Time): Application has thrown an uncaught exception and is terminated:
- Error: Cannot find module 'merge-descriptors'
- Require stack:
- - D:\home\site\wwwroot\node_modules\express\lib\express.js
- - D:\home\site\wwwroot\node_modules\express\index.js
- - D:\home\site\wwwroot\index.js
- - D:\Program Files (x86)\iisnode\interceptor.js
- at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
- at Function.Module._load (internal/modules/cjs/loader.js:667:27)
- at Module.require (internal/modules/cjs/loader.js:887:19)
- at require (internal/modules/cjs/helpers.js:74:18)
- at Object.<anonymous> (D:\home\site\wwwroot\node_modules\express\lib\express.js:17:13)
- at Module._compile (internal/modules/cjs/loader.js:999:30)
- at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
- at Module.load (internal/modules/cjs/loader.js:863:32)
- at Function.Module._load (internal/modules/cjs/loader.js:708:14)
- at Module.require (internal/modules/cjs/loader.js:887:19)
- Mon Jan 24 2022 11:11:35 GMT+0000 (Greenwich Mean Time): Application has thrown an uncaught exception and is terminated:
- Error: Cannot find module 'finalhandler'
- Require stack:
- - D:\home\site\wwwroot\node_modules\express\lib\application.js
- - D:\home\site\wwwroot\node_modules\express\lib\express.js
- - D:\home\site\wwwroot\node_modules\express\index.js
- - D:\home\site\wwwroot\index.js
- - D:\Program Files (x86)\iisnode\interceptor.js
- at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
- at Function.Module._load (internal/modules/cjs/loader.js:667:27)
- at Module.require (internal/modules/cjs/loader.js:887:19)
- at require (internal/modules/cjs/helpers.js:74:18)
- at Object.<anonymous> (D:\home\site\wwwroot\node_modules\express\lib\application.js:16:20)
- at Module._compile (internal/modules/cjs/loader.js:999:30)
- at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
- at Module.load (internal/modules/cjs/loader.js:863:32)
- at Function.Module._load (internal/modules/cjs/loader.js:708:14)
- at Module.require (internal/modules/cjs/loader.js:887:19)
然后,直接从本地项目文件夹 node_modules 中的内容 上传到 App Service 中,即可解决 connot find module ‘ **** ’ 错误。
附录二:示例代码
下载地址:https://files.cnblogs.com/files/lulight/nodejs-express-azuermobileapp-web.confg.zip?t=1643031258
参考资料
Create a Node.js web app in Azure:https://docs.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=windows&pivots=development-environment-vscode
Node.js Hello World in App Service: https://github.com/Azure-Samples/nodejs-docs-hello-world
【Azure 应用服务】Azure Mobile App (NodeJS) 的服务端部署在App Service for Windows中出现404 Not Found -- The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.的更多相关文章
- nodejs 开发服务端 部署到 iis 服务器环境 -- iisnode 安装问题解决记录
开发环境 nodejs: v10.15.3 windows: 10 iis: 10 需求: 用Nodejs开发了服务端,要部署到IIS 需要在IIS服务器上安装iisnode,结果遇到问题:安装不上 ...
- 借助Nodejs在服务端使用jQuery采集17173游戏排行信息
Nodejs相关依赖模块介绍 Nodejs的优势这里就不做介绍啦,这年头相信大家对它也不陌生了.这里主要介绍一下用到的第三方模块. async:js代码中到处都是异步回调,很多时候我们需要做同步处理, ...
- 示例 - 25行代码等价实现 - 借助Nodejs在服务端使用jQuery采集17173游戏排行信息
今天在园子里看到一篇文章: 借助Nodejs在服务端使用jQuery采集17173游戏排行信息 感觉用SS来实现相同功能更加简洁, 于是写了一下, 发现25行代码就搞定了 (包括自动翻页), 于是跟大 ...
- nodejs实现服务端重定向
nodejs实现服务端重定向:https://www.jianshu.com/p/5a1500fcd713
- 内网穿透神器(ngrok)服务端部署【分享一台自己的ngrok服务器】【多平台】
Ngrok为何物 “ngrok 是一个反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道.ngrok 可捕获和分析所有通道上的流量,便于后期分析和重放.”这是百度百科上给Ng ...
- CAS单点登录之服务端部署
一.CAS服务端搭建 1.1 CAS支持Http登录配置 CAS默认是要https的链接才能登录的,不过学习的话是可以先去掉https限制,本博客介绍的是基于Cas4.2.7的,之前改过4.0的,详情 ...
- Rsync服务端部署流程
Rsync服务端部署流程 Rsync服务端部署流程: 一.rsync服务端配置流程 配置rsync配置文件/etc/rsyncd.conf 创建同步的本地目录/dingjian 并根据需要 ...
- Zabbix5.0服务端部署
Zabbix5.0服务端部署 基础环境配置 [root@localhost ~]# systemctl disable --now firewalld Removed symlink /etc/sys ...
- 【Azure 应用服务】在 App Service for Windows 中自定义 PHP 版本的方法
问题描述 在App Service for Windows的环境中,当前只提供了PHP 7.4 版本的选择情况下,如何实现自定义PHP Runtime的版本呢? 如 PHP Version 8.1.9 ...
随机推荐
- SpringCloud(四) config
Spring Cloud Config 在分布式系统中,尤其是当我们的分布式项目越来越多,每个项目都有自己的配置文件,对配置文件的统一管理就成了一种需要,而 Spring Cloud Config 就 ...
- 一个windows主题网站-
地址 地址 说明 选择适合自己的,下载,双击安装,就可使用了
- 【九度OJ】题目1176:树查找 解题报告
[九度OJ]题目1176:树查找 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1176 题目描述: 有一棵树,输出某一深度的所有节点 ...
- Pikachu漏洞练习-SQL-inject(持续更新)
本来在bup中repeater模式可以多次测试,但不知为何总是出错 这里把我们想查询的数据库和版本进行联合查询,放包,页面回显数据库名称和版本分别为pikachu,5.7.26 数据库版本大于5那么i ...
- AOP 日志切面
AOP把软件的功能模块分为两个部分:核心关注点和横切关注点.业务处理的主要功能为核心关注点,而非核心.需要拓展的功能为横切关注点.AOP的作用在于分离系统中的各种关注点,将核心关注点和横切关注点进行分 ...
- HITCON 2019 Lost Modular again writeup
HITCON 2019 Lost Modular again writeup 算是基础题,有很多之前题的影子,做不出来纯属菜. 题目 加密脚本 from Crypto.Util.number impo ...
- 「算法笔记」Link-Cut Tree
一.简介 Link-Cut Tree (简称 LCT) 是一种用来维护动态森林连通性的数据结构,适用于动态树问题. 类比树剖,树剖是通过静态地把一棵树剖成若干条链然后用一种支持区间操作的数据结构维护, ...
- 【2021/12/31】uniapp之安卓原生插件开发教程
uniapp之安卓原生插件开发教程 准备 hbuilderX,下载 app离线SDK,下载 Andorid Studio,安卓官方或中文社区 证书(可以自己准备,也可以使用android Studio ...
- 读书笔记markdown模板
读书笔记 书名 作者 出版社 阅读日期 书籍背景 书摘/ 笔记 批注 总结& 收获 读完每一本书,把书中的知识转化为「自己的智慧」,才是最扎实的收获- 他山之石 摘录相关精彩书评-
- [Error]ValueError: Object arrays cannot be loaded when allow_pickle=False
问题描述使用numpy的函数 numpy.load() 加载数据时报错: ValueError: Object arrays cannot be loaded when allow_pickle=Fa ...