Azure App Service部署Node.js基础服务器遇403.14禁止错误求助
解决Azure App Service部署Node.js出现HTTP Error 403.14 - Forbidden的问题
你的问题核心在于web.config缺少IISNode的关键配置,导致IIS无法将请求转发给Node.js运行时处理,同时默认文档未包含Node.js的入口文件index.js。以下是具体的修复步骤:
1. 更新web.config配置
替换现有web.config为以下内容,它包含了IISNode映射、URL重写规则以及详细错误配置:
<configuration> <system.webServer> <httpErrors errorMode="Detailed" /> <asp scriptErrorSentToBrowser="true"/> <!-- 配置IISNode关联Node.js入口文件 --> <iisnode nodeProcessCommandLine="node.exe" /> <!-- URL重写:将所有请求导向index.js --> <rewrite> <rules> <rule name="Node.js" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.js" /> </rule> </rules> </rewrite> <!-- 添加index.js到默认文档列表 --> <defaultDocument> <files> <add value="index.js" /> <add value="index.html" /> </files> </defaultDocument> </system.webServer> <system.web> <customErrors mode="Off"/> <compilation debug="true"/> </system.web> </configuration>
配置说明:
<iisnode>:告诉IIS使用node.exe来处理.js文件- URL重写规则:确保所有非文件/非目录的请求都转发到index.js,适配Express的路由机制
<defaultDocument>:将index.js加入默认文档优先级,当访问根路径时优先触发Node.js入口
2. 确认package.json配置
确保你的项目根目录下有package.json,并且包含start脚本(Azure App Service会自动识别这个脚本启动Node.js应用):
{ "name": "networth-tracker-api", "version": "1.0.0", "scripts": { "start": "node index.js" }, "dependencies": { "express": "^4.18.2" } }
如果之前没有package.json,运行npm init -y生成,再安装依赖npm install express。
3. 验证Azure App Service设置
- 进入Azure门户的App Service资源,在配置 > 常规设置中,确认启动命令为空(Azure会自动读取package.json的start脚本),或者设置为
npm start - 检查运行时堆栈是否选择了正确的Node.js版本(建议和本地开发版本一致)
完成以上配置后,重新部署你的应用,403.14错误应该会被解决,根路径会正确返回Express的响应内容。
内容的提问来源于stack exchange,提问作者Anu
相关产品推荐
相关产品推荐

