NGINX Run multiple application on same port with different route path

萝らか妹 提交于 2021-02-16 14:58:05

问题


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.

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;
     }

}

As the above configuration is working for only, First default root path. The other /application-2 is not able to redirect to specified path.

Any help will be appreciated.

Thanks Praveen T


回答1:


As a quick hack, try either

location /application-2/ {
    proxy_pass http://application-2:2345/;
    ...
}

or

location /application-2/ {
    rewrite ^/application-2(.*) $1 break;
    proxy_pass http://application-2:2345;
    ...
}

but you'd better build you angular app according to your URI prefix, see instructions here. Then your original config should work as expected.



来源:https://stackoverflow.com/questions/62759181/nginx-run-multiple-application-on-same-port-with-different-route-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!