Repository: next.js
Issue: Middleware and custom server randomly causes `uncaughtException` `error: aborted` when work with nginx using `error_page`
Labels: bug,Runtime

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101
    Binaries:
      Node: 16.13.1
      npm: 8.1.2
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.4.2-canary.4
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

### Link to the code that reproduces this issue

/

### To Reproduce

1. Set up nginx and run with config:
```nginx
server {
    listen 80;
    server_name _;

    location / {
      proxy_pass http://host.lima.internal:3000;

    }

    location /not_found {
      return 404 "The requested 1 resource was not found";
    }

    proxy_intercept_errors on;

    error_page 404 /not_found;
  }
```
2. Add `middleware.js` file inside `/src`
```js
//middleware.js
import { NextResponse } from 'next/server';

export async function middleware(req, event) {
  console.log(`[*] Request new: ${req.url}`);
  return NextResponse.next();
}
```
3. Add custom server inside `/src`:
```js
//server.js
const express = require('express');
const next = require('next');

const dev = process.env.NODE_ENV !== 'production';
const hostname = 'localhost';
const port = 3000;


process.on('uncaughtException', (error) => {
  console.error('Uncaught Exception log :', error);
})

const app = next({
  dev,
  hostname,
  port
});
const handler = app.getRequestHandler();

app.prepare().then(() => {
    const server = express();
    server.all('*', (req, res) => {
      return handler(req, res);
    });

    server.listen(3000, (err) => {
      if (err) {
        console.log(err);
        process.exit(1);
      }

      console.log(`> Listening on http://:3000`);
    });
});
```

4. Set up script run custom server:
  ```js
  "scripts": {
    "dev": "next dev",
    "start": "NODE_ENV=production node src/server.js",
    "start-next": "next start",
    "build": "next build",
    "lint": "next lint"
  },
  ```
5. run nginx proxy in local machine
6. run `npm run build`
7. run `npm run start`
8. run fetch requests in console window:
```js
for (let index = 0; index < 120; index++) {
    fetch(`http://localhost/hyusy/isisom${index}`, {
      "headers": {
        "accept": "application/json, text/plain, */*",
        "accept-language": "en-US,en;q=0.9",
        "cache-control": "no-cache",
        "content-type": "application/json",
        "sec-fetch-dest": "empty"
      },
      "referrerPolicy": "unsafe-url",
      "body": "{}",
      "method": "POST",
      "credentials": "include"
    });
}
```
9. Randomly cause an error `Error: aborted`
```
Uncaught Exception log : Error: aborted
    at connResetException (node:internal/errors:691:14)
    at abortIncoming (node:_http_server:596:17)
    at socketOnClose (node:_http_server:590:3)
    at Socket.emit (node:events:402:35)
    at TCP.<anonymous> (node:net:687:12) {
  code: 'ECONNRESET'
}
```

### Describe the Bug

- Randomly cause an error Error: aborted
```
Uncaught Exception log : Error: aborted
    at connResetException (node:internal/errors:691:14)
    at abortIncoming (node:_http_server:596:17)
    at socketOnClose (node:_http_server:590:3)
    at Socket.emit (node:events:402:35)
    at TCP.<anonymous> (node:net:687:12) {
  code: 'ECONNRESET'
}
```
- This error occurs when using both custom server and middleware and nginx proxy (with `error_page 404 /not_found`).
- The error does not occur when we do not use the middleware, nginx, or a custom server.
- The error does not occur when we use nginx proxy without `error_page 404 /not_found`.
- The error does not occur when we do not use custom server, we start with `next start`.

### Expected Behavior

Nextjs should not throw the uncaughtException

### Which browser are you using? (if relevant)

Chrome 112.0.5615.137

### How are you deploying your application? (if relevant)

using custom server and local