We're hosting 2 Angular applications on one Linux server running nginx. We'd like to have use same hostname within 2 Angular apps. Let's say when I browse to http://example.com, it'll use one of these apps, but if I browse to a specific page, it'd use the other one. I can't seem to get this to work.
So we have http://example.com (app1) that serves dynamic content
and
we have http://example.com/app2 and http://example.com/app2_subpage that are used by the app2 and also serve dynamic content
Both of these apps are meant to run together as they are different services of one whole system, that's why we want to run them under same machine/DNS.
nginx conf:
server {
listen 80;
server_name example.com;
location ~ ^/(app2|app2_subpage)/ {
root /path/to/app2;
try_files $uri$args $uri$args/ /index.html;
}
location / {
root /path/to/app1;
try_files $uri$args $uri$args/ /index.html;
}
}
So the http://example.com(app1) works with all its dynamic content but http://example.com/app2 and http://example.com/app2_subpage gets redirected back to http://example.com(app1).
It seems that the regex for the app2 location block isn't correct. What would be the configuration in this case?