next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Reverse proxy problems.

Open zZHorizonZz opened this issue 1 year ago • 6 comments

Link to the code that reproduces this issue

https://github.com/zZHorizonZz/nextjs-routing

To Reproduce

  1. Start the application
  2. Create a new reverse proxy nginx or IIS and have it route requests for path test for example. (In the repro repository there is an attached file for IIS page config with rewrite rule configuration)
  3. Try to access the site

Current vs. Expected behavior

Current behavior works like this:

  1. IIS Rewrite test -> localhost:3000 (http://localhost/test) This will get the index file but other files are not found as it's pointing to localhost/_next
  2. IIS Rewrite test -> localhost:3000 with basePath set to test (http://localhost/test) no file is found even the index file (404)
  3. IIS Rewrite test -> localhost:3000/test with basePath set to test (http://localhost/test) results in error too many redirects

The expected behavior is this should probably route and return the correct files. I found a related discussion to this here

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Enterprise
Binaries:
  Node: 20.9.0
  npm: N/A
  Yarn: N/A
  pnpm: 8.6.2
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Routing (next/router, next/navigation, next/link)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

No response

zZHorizonZz avatar Jan 22 '24 08:01 zZHorizonZz

Facing similar issues with nginx and nextjs 14.1.0

gitgetgud avatar Jan 22 '24 10:01 gitgetgud

Duplicate? Removing trailing / fixed my issue

gitgetgud avatar Jan 22 '24 11:01 gitgetgud

Duplicate? Removing trailing / fixed my issue

I don't think this is related to my case as I don't have any trailing / in any of the settings.

zZHorizonZz avatar Jan 25 '24 06:01 zZHorizonZz

After looking into it more closely, I've noticed something unusual. Even the default application returns a 404 error, but the issue is more complex. We receive a valid index response, which includes references to subsequent scripts and other elements, so the responses themselves appear valid. However, something occurs subsequently, and Next.js sets the status of response to 404. The only explanation I can think of is that there might be an issue with invalid headers. Could this be the reason Next.js is marking the request as 404? But that's just a wild guess.

zZHorizonZz avatar Jan 26 '24 11:01 zZHorizonZz

After looking into it more closely, I've noticed something unusual. Even the default application returns a 404 error, but the issue is more complex. We receive a valid index response, which includes references to subsequent scripts and other elements, so the responses themselves appear valid. However, something occurs subsequently, and Next.js sets the status of response to 404. The only explanation I can think of is that there might be an issue with invalid headers. Could this be the reason Next.js is marking the request as 404? But that's just a wild guess.

do the scripts in the index all have the appropriate basePath prepended?

willmeierart avatar Jan 31 '24 20:01 willmeierart

After looking into it more closely, I've noticed something unusual. Even the default application returns a 404 error, but the issue is more complex. We receive a valid index response, which includes references to subsequent scripts and other elements, so the responses themselves appear valid. However, something occurs subsequently, and Next.js sets the status of response to 404. The only explanation I can think of is that there might be an issue with invalid headers. Could this be the reason Next.js is marking the request as 404? But that's just a wild guess.

do the scripts in the index all have the appropriate basePath prepended?

Yes, it does, but I have noticed that when I go to the default path, Next.js starts building the not-found page, which seems weird.

zZHorizonZz avatar Feb 01 '24 11:02 zZHorizonZz

I also have this issue..

encloinc avatar Feb 26 '24 01:02 encloinc