【发布时间】:2022-02-07 04:32:31
【问题描述】:
我有两个 nextjs 应用在端口 3000 和 3001 上运行,我的 Nginx 配置如下
events {
worker_connections 1024;
}
http {
server {
listen 8080;
server_name http://localhost:8080;
proxy_buffering off;
proxy_http_version 1.1;
location / {
proxy_pass http://localhost:3000/;
proxy_redirect off;
}
location ^~ /app {
proxy_pass http://localhost:3001/;
proxy_redirect off;
}
}
}
NextJS 应用在 3000 端口上运行良好。
- 当我访问 localhost:8080 - 它按预期从端口 3000 加载应用程序。
但是通过 nginx URL 访问 3001 端口上的第二个应用是不可能的
- 当我访问 localhost:8080/app - 它从端口 3000 加载应用程序。
- 当我访问 localhost:8080/app/ 时,它会将 URL 更改为 localhost:8080 并从端口 3000 加载应用程序。
- 当我访问 localhost:8080/app/login - 它将 URL 更改为 localhost:8080/login 并加载 404,因为端口 3000 上的应用程序没有登录路由。
我在这个配置中有什么遗漏吗?
【问题讨论】:
标签: nginx next.js nginx-ingress