Node.js Express应用程序只能通过本地主机工作,不能通过网络工作(找不到文件或目录)?
我正在尝试创建一个node.js express应用程序,该应用程序应该位于IIS服务器上,并通过internet访问。然而,到目前为止,我只能通过localhost实现这一点。My node.js应用程序在通过本地计算机上的localhost和Windows Server 2012 R2计算机上的IIS访问时工作,但尝试通过URL或IP访问时返回以下页面: 我不确定到底发生了什么,但在过去的一天里,我一直在为这件事绞尽脑汁。如果有人有任何想法,并可以在这方面提供一些线索,将不胜感激 这是我的app.js(.env文件不包含端口或IP变量,仅用于密钥) 用于路由的index.jsNode.js Express应用程序只能通过本地主机工作,不能通过网络工作(找不到文件或目录)?,node.js,express,networking,localhost,iisnode,Node.js,Express,Networking,Localhost,Iisnode,我正在尝试创建一个node.js express应用程序,该应用程序应该位于IIS服务器上,并通过internet访问。然而,到目前为止,我只能通过localhost实现这一点。My node.js应用程序在通过本地计算机上的localhost和Windows Server 2012 R2计算机上的IIS访问时工作,但尝试通过URL或IP访问时返回以下页面: 我不确定到底发生了什么,但在过去的一天里,我一直在为这件事绞尽脑汁。如果有人有任何想法,并可以在这方面提供一些线索,将不胜感激 这是我的
var express = require('express');
var router = express.Router();
var sfdcSystemController = require('../controllers/Salesforce/SystemController.js');
var jwt = require('jsonwebtoken');
var fs = require('fs');
router.get('/',sfdcSystemController.doGet);
module.exports = router;
iisnode的web.config
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="nodejs">
<match url="api/*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/app.js" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
<add segment="iisnode" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
解决了我的问题。事实证明,IIS及其在服务器上的配置方式与我的代码所做的相比更像是一个问题 在IIS中,我必须执行以下操作才能使node.js应用程序正常工作
这看起来更像是一个网络问题,请求从未到达node.js服务器。发现问题,实际上是一个IIS问题。答案如下。
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="nodejs">
<match url="api/*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/app.js" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
<add segment="iisnode" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>