How to fix issue about iisnode when deploy NextJS web into azure host via azure web service

Vinh Nguyen 0 Reputation points
2024-12-16T08:05:34.3866667+00:00

Here issue when I log:
Error 500.1013 - Internal Server Error

The page cannot be displayed because an internal server error has occurred.

Most likely causes:

IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.

IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.

IIS was not able to process configuration for the Web site or application.

The authenticated user does not have permission to use this DLL.

The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Things you can try:

Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.

Check the event logs to see if any additional information was logged.

Verify the permissions for the DLL.

Install the .NET Extensibility feature if the request is mapped to a managed handler.

Create a tracing rule to track failed requests for this HTTP status code.

Detailed Error Information: Module: iisnode Notification: ExecuteRequestHandler Handler: iisnode Error Code: 0x0000006d Requested URL: https://app-eskimo-www-prod-sea-001__2256:80/server.js Physical Path: C:\home\site\wwwroot\server.js Logon Method: Anonymous Logon User: Anonymous

More Information: This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,093 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shree Hima Bindu Maganti 1,585 Reputation points Microsoft Vendor
    2024-12-19T19:15:06.4466667+00:00

    Hi Vinh Nguyen
    Welcome to the Microsoft Q&A Platform!
    The error is Error 500.1013 - Internal Server Error, suggests that there is an issue with your Azure Web App configuration when deploying your Next.js application using iisnode.
    Verify Deployment Structure. Build your Next.js app locally.
    npm run build
    check the following directories/files are deployed properly .

    .next

    node_modules

    package.json

    Any custom server.js or index.js file
    Use this web.config template.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <handlers>
          <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
          <rules>
            <rule name="DynamicContent">
              <match url=".*" />
              <action type="Rewrite" url="server.js" />
            </rule>
          </rules>
        </rewrite>
        <iisnode watchedFiles="web.config;server.js" />
      </system.webServer>
    </configuration>
    

    Replace server.js with the actual entry point of your application.
    Ensure server.js or Entry Point is Correct .

    server.js for Next.js.

    const { createServer } = require('http');
    const next = require('next');
    const app = next({ dev: false });
    const handle = app.getRequestHandler();
    app.prepare().then(() => {
      createServer((req, res) => {
        handle(req, res);
      }).listen(process.env.PORT || 3000);
    });
    

    Add PORT environment variable ( 3000).

    Set WEBSITE_NODE_DEFAULT_VERSION to a compatible Node.js version (18.x).

    Ensure the wwwroot directory grants read/write permissions to the Application Pool Identity.

    Enable .NET Extensibility 4.x.

    Ensure iisnode is installed and configured correctly.

    Open IIS Manager > Select Your Site > Add Failed Request Tracing for 500 errors.

    Analyze logs for more details.
    ref: Azure Web App Node.js Documentation

    IISNode Documentation

    Failed Request Tracing in IIS
    If this doesn't resolve the issue, please share additional logs or configuration details for deeper analysis.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.