如何使用IIS解决node.js上的404错误?

时间:2019-04-03 15:00:31

标签: node.js iis iisnode

我正在开发一个nodejs应用程序。尝试转到我的路线时,Node.js出现404错误。

一切都可以在localhost上正常运行,但是在发布到iis服务器后,nodejs转到我的路由时会出现404错误。

我要走的路线是“ / admin”。 IIS将此路由检测为物理路径。但是我没有在代码中定义它。

Error Image

可以帮我吗?

已解决问题。当我将此规则添加到web.config文件中时,问题已解决:

    <rewrite>
            <rules>
                <rule name="sendToNode">
                    <match url="/*" />
                    <action type="Rewrite" url="app.js" />
                </rule>
            </rules>
        </rewrite>

app.js:

import express from "express";
import bodyParser from "body-parser";
import expressLayout from "express-ejs-layouts";
import path from "path";
var app = express();

import AuthService from "./app_server/service/AuthService";
AuthService.Init(app);

import AdminRouter from "./app_server/router/admin/AdminRouter";
process.env.NODE_ENV = "production";
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "./app_server/view"));
app.use(expressLayout);
app.use(bodyParser.json());
app.use("/public", express.static("./public"));
app.use("/uploads", express.static("./uploads"));

app.set("layout extractScripts", true);
AdminRouter.init(app);
app.get("/", (req, res) => {
  res.json(req.isAuthenticated());
});

app.listen(process.env.port || 8000, () => {
  console.log("Started at 8000 port.");
});

web.config:

<configuration>
  <system.webServer>

    <!-- indicates that the hello.js file is a node.js application 
    to be handled by the iisnode module -->

    <handlers>
      <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
    </handlers>

    <iisnode      
      node_env="%node_env%"
      nodeProcessCountPerApplication="1"
      maxConcurrentRequestsPerProcess="1024"
      maxNamedPipeConnectionRetry="100"
      namedPipeConnectionRetryDelay="250"      
      maxNamedPipeConnectionPoolSize="512"
      maxNamedPipePooledConnectionAge="30000"
      asyncCompletionThreadCount="0"
      initialRequestBufferSize="4096"
      maxRequestBufferSize="65536"
      watchedFiles="*.js;iisnode.yml"
      uncFileChangesPollingInterval="5000"      
      gracefulShutdownTimeout="60000"
      loggingEnabled="true"
      logDirectory="iisnode"
      debuggingEnabled="true"
      debugHeaderEnabled="false"
      debuggerPortRange="5058-6058"
      debuggerPathSegment="debug"
      maxLogFileSizeInKB="128"
      maxTotalLogFileSizeInKB="1024"
      maxLogFiles="20"
      devErrorsEnabled="true"
      flushResponse="false"      
      enableXFF="false"
      promoteServerVars=""
      configOverrides="iisnode.yml"
     />
  </system.webServer>
</configuration>

0 个答案:

没有答案