Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple apps on same domain, on different hosts #9266

Closed
michelhelms-tdg opened this issue Oct 31, 2019 · 5 comments
Closed

Support multiple apps on same domain, on different hosts #9266

michelhelms-tdg opened this issue Oct 31, 2019 · 5 comments

Comments

@michelhelms-tdg
Copy link

Feature request

Is your feature request related to a problem? Please describe.

I want to have example.org/docs on host1 and example.org/docs on host2.

That means there would be a reverse proxy that would split traffic depending on the path and direct it to either host1 or host2. This is currently not possible with next.js, because both apps will produce _/next/static folders that the upstream reverse proxy can not tell apart.

Describe the solution you'd like

Ideally next.js would have strong support for a "basepath"-like solution so that all site-internal links, all assets and all files from _/next/static would get adjusted. Maybe even just a "chunksPath" because everything but the _/next/static folder can be solved.

Describe alternatives you've considered

  • There is the assetPrefix configuration but when for example set to /docs the server issues requests for /docs/_next/static/... which all go 404
  • The Multi-Zones (doc, example) work well to have separated apps on the same host but not for on separate hosts

Additional context

I found similar requests in #5602 and #257.

@timneutkens
Copy link
Member

Based on your explanation assetPrefix / zones is all you need to get this working, your explanation is not super clear though but I guess you want to set 2 different assetPrefix values.

With regards to having a basepath that's already tracked in #4998.

@michelhelms-tdg
Copy link
Author

Based on your explanation assetPrefix / zones is all you need to get this working

I even describe how assetPrefix and zones are not working in this case.

Thanks for the hint at #4998 though, that would solve my problem.

@timneutkens
Copy link
Member

Based on what you're describing they would work. I guess you're making assumptions about the url being a certain shape though hence why you want basepath.

@NimitMak
Copy link

I handled this issue via Nginx Routing.

What i assumed while making this Nginx Routing is that every file will have unique hash and file name combination.

This is the snippet of code of Nginx Routing which i used.

location /static/ {
    try_files $uri @server1;
}
location @server1{
    proxy_pass http://192.168.1.1$uri;
    proxy_intercept_errors on;
    recursive_error_pages on;
    error_page 404 = @server2;
}

location @server2{
    proxy_pass http://192.168.1.2$uri;
    proxy_intercept_errors on;
    recursive_error_pages on;
    error_page 404 = @server3;
}

location @server3{
    proxy_pass http://192.168.1.3$uri;
}

What the above code does is, whenever Nginx encounters /_next/ it will first try that URL with @server1, if that Server responds with 404, the Nginx then transfers the request to @server2 as mentioned in error_page param.

This example works like:
try_files $uri @server1 @server2 @server3

This worked for me as i had 2 apps which were developed on Next and both has _next route.

Let me know if this solves your problem.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants