Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX Run multiple application on same port with different route path

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

like image 992
praveen2609 Avatar asked Sep 07 '25 00:09

praveen2609


1 Answers

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.

like image 117
Ivan Shatsky Avatar answered Sep 09 '25 00:09

Ivan Shatsky