【问题标题】:Deploying NextJS app on IIS web server not working在 IIS Web 服务器上部署 NextJS 应用程序不起作用
【发布时间】:2022-01-17 23:30:29
【问题描述】:

您好,我的任务是将我们的下一个 Web 应用程序部署到 IIS Windows 服务器,但无法弄清楚如何解决我遇到的这个问题。

我只有一个基本的 create-next-app,几乎没有代码尝试将其部署到服务器并正常工作。

我已经阅读过,似乎遇到了权限问题,但从大量阅读中我似乎无法弄清楚我需要更改什么

这里是我当前位于根目录中的 web.config 和 server.js。

<configuration>
  <system.webServer>

    <webSocket enabled="false" />
    <handlers>
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>

        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>


        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>
    
      <requestFiltering>
        <hiddenSegments>
          <add segment="node_modules"/>
        </hiddenSegments>
      </requestFiltering>
    </security>
    <httpErrors existingResponse="PassThrough" />
   <iisnode node_env="production" />
  
  </system.webServer>
</configuration>
const {createServer} = require('http');
const {parse} = require('url');
const next = require('next');

const dev = process.env.NODE_ENV !== 'production';
const app = next({dev});
const port = process.env.PORT || 3000;
const handle = app.getRequestHandler();

app.prepare().then(() => {
  createServer((req, res) => {
    // Be sure to pass `true` as the second argument to `url.parse`.
    // This tells it to parse the query portion of the URL.
    const parsedUrl = parse(req.url, true);
    const {pathname, query} = parsedUrl;

    if (pathname === '/a') {
      app.render(req, res, '/a', query);
    } else if (pathname === '/b') {
      app.render(req, res, '/b', query);
    } else {
      handle(req, res, parsedUrl);
    }
  }).listen(port, err => {
    if (err) throw err;
  });
});

我按照这个教程https://www.youtube.com/watch?v=HLsx0iraA-Y

【问题讨论】:

  • 正如错误消息所说,您需要更多信息来解决您的问题,您可以使用 ETW 跟踪或失败的请求跟踪来获取详细信息

标签: reactjs iis deployment next.js web-config


【解决方案1】:

我对 NextJs 一无所知,但是

错误:EPERM:不允许操作,lstat 'C:\Users\hunte'

似乎表明 IIS 进程想要访问您的用户目录。使用默认 IIS 权限,应用程序池进程无权访问任何用户目录。

C:\Users\hunte 下是否有您的应用程序文件?将它们移动到用户组具有读取权限的其他位置。

还有:

HTTP 子状态:1002

这看起来不像 IIS 子状态,我从来没有 1002。

【讨论】:

  • 我愿意,它目前只是在我的本地计算机桌面上。我相当肯定你所描述的是问题,我只是不知道如何从这里开始,因为直到现在我从未使用过 IIS。
  • 我将整个项目文件夹移到 C:/Users 中,现在可以使用了哈哈,非常感谢您的回复!
猜你喜欢
  • 2014-04-28
  • 1970-01-01
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-04
  • 2013-12-06
  • 1970-01-01
相关资源
最近更新 更多