Nginx redirect to different domain based on subdirectory

Solution 1:

location /subdir/ matches requests where URI is /subdir/.

In your example request, URI is /subdir. Therefore that location block is not used.

The request is then processed by location /, and then the index.php of that application does something.

To make /subdir to go to the same location, you need to add another location block:

location = /subdir {
        proxy_pass http://127.0.0.1:8080/;
        proxy_redirect off;
        proxy_buffer_size 128k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;
}

The = attribute makes this an exact match, and it is processed first by nginx.