我有两个 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;
}
}
}
端口 3000 上的 NextJS 应用程序运行良好。
- 当我访问 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 上的应用程序没有登录路由。
我在这个配置中缺少什么吗?
put ^~ /app
之前阻塞/
堵塞 。较高的块具有优先权并且/
块就像......对于一切。
location ^~ /app {
proxy_pass http://localhost:3001/;
proxy_redirect off;
}
location / {
proxy_pass http://localhost:3000/;
proxy_redirect off;
}
除 /app 之外的任何内容都将进入第二个块。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)