Skip to content

basePath doesn't work for all assets when serves at sub path #80602

Open
@T3-T4n

Description

@T3-T4n

Link to the code that reproduces this issue

https://github.com/SigNoz/sample-nextjs-app.git

To Reproduce

  1. get a sample app. git clone https://github.com/SigNoz/sample-nextjs-app.git
  2. copy official Dockerfile to the sample project (https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile)
  3. set output to standalone and add basePath, assetPrefix according to the official document
output: 'standalone',
basePath: '/myapp',
assetPrefix: '/myapp',
  1. build docker image and run.
  2. modify nginx config to forward proxy
        location /myapp/ {
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://localhost:3000/; 
        }
    }
  1. run nginx with the new config
  2. on another machine, open a browser and try to access to https://my-server.com/myapp/
  3. try to access to http://my-server.com:3000 without proxy

Current vs. Expected behavior

Current:
When I access to proxy link https://my-server.com/myapp/
Nextjs still tries to look for some assets from root /, not /myapp which make only part of style, images looks good.
Image

If I access to my app without proxy: http://my-server.com:3000, everything looks good.

Image

Expected:
The page should load all assets even I'm accessing sub path to my app.

Provide environment information

Operating System:
  Platform: Ubuntu
  Arch: x64
  Version: 24.04.1 LTS
Binaries:
  Node: coming from 18-alpine docker image
  npm: coming from 18-alpine docker image

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

Not Found, Runtime

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

Other (Deployed)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not FoundRelated to the not-found.tsx file or the notFound() function.RuntimeRelated to Node.js or Edge Runtime with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions