Nginx uses the path to redirect to the service

three services ServiceA, ServiceB, ServiceC, are deployed on the server corresponding to the domain name www.services.com,
the access method for each service is to access the index.html file of the corresponding path. For example, the front-end path of the ServiceA service is the front-end path of the Path/to/A, ServiceB service, and the front-end path of the Path/to/A, ServiceB service is pATh/tO/B

.

then I wanted to access Path/to/A/index.html, through http://www.services.com/ServiceA, so I tried this configuration:

http {
  listen 80;
  server_name www.services.com;

  -sharp nginx
  location /  {
    root html;
    index index.html index.htm
  }

  -sharp ServiceA
  locaton ^~ /ServiceA {
    root Path/to/A
    index.index.html index.htm
  }
}

and finally will actually request access to / Path/to/A/ServiceA/ or / usr/share/nginx/html/ServiceA/, and return 404 error.

Why is there such a routing rule? How to achieve the desired results?


you can use try files to solve

-sharp ServiceA 
locaton ^~ /ServiceA { 
    root Path/to/A ;
    -sharpindex.index.html index.htm 
    try_files $url  index.html;
}

  index index.html index.htm;
  locaton /ServiceA/ {
    alias Path/to/A/;
  }
  locaton /ServiceB/ {
    alias Path/to/B/;
  }
  locaton /ServiceC/ {
    alias Path/to/C/;
  }
Menu