NGINX 在具有不同路由路径的同一端口上运行多个应用程序
我有两个应用程序,app1 在 reactJS 中开发,app2 在 angularJS 中开发,共享相同的登录会话,
I have two applications, app1 is developed in reactJS and app2 in angularJS sharing same login session,
- Application 1
http://application-1:1234/
- APplication 2
http://application-2:2345/
我需要在两个应用之间进行无缝导航,因为它们共享相同的登录凭据.
My needs is to have a seemless navigation between both apps, as they share the same login credentials.
我已经创建了 NGINX 反向代理配置,
I have created NGINX reverse proxy configuration,
server {
listen 8080;
server_name http://global-ip:8080;
location / {
proxy_pass http://application-1:1234;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /application-2 {
proxy_pass http://application-2:2345;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
由于上述配置仅适用于,第一个默认根路径.另一个/application-2 无法重定向到指定路径.
As the above configuration is working for only, First default root path. The other /application-2 is not able to redirect to specified path.
任何帮助将不胜感激.
谢谢普雷文T
作为一个快速的 hack,尝试其中之一
As a quick hack, try either
location /application-2/ {
proxy_pass http://application-2:2345/;
...
}
或
location /application-2/ {
rewrite ^/application-2(.*) $1 break;
proxy_pass http://application-2:2345;
...
}
但你最好根据你的 URI 前缀构建你的 angular 应用程序,请参阅说明
but you'd better build you angular app according to your URI prefix, see instructions here. Then your original config should work as expected.