When nginx receives a request, it first tries to match the outer location block. If it finds one, it then checks if any nested location blocks inside it match the request more specifically. If a nested location matches, nginx uses its configuration, such as root or proxy settings, to serve the request. If no nested location matches, nginx uses the outer location's settings. If the request does not match the outer location at all, nginx skips nested checks and uses the default server behavior. For example, a request to /app/images/logo.png matches the outer /app/ location and the nested /app/images/ location, so nginx uses the nested root /var/www/images. A request to /app/index.html matches only the outer location, so it uses /var/www/html. This layered matching helps organize configurations clearly and apply specific rules where needed.