Nginx reverse proxy to another nginx server serving static files

Solution 1:

You generally don't need to add the path to nginx!

The path from the location gets added automatically

so this

location /app/ {
      proxy_pass http://server1.com:8000/app/;
}

should really be:

 location /app/ {
      proxy_pass http://server1.com:8000;
}

Solution 2:

The problem is your second nginx instance that's trying to serve files locally:

   location / {
           try_files $uri $uri/ =404;
      }

Just remove that whole thing if you want to serve using http://server2.com/app/. If you want to use http://server2.com/ instead, update the config to reflect that:

  listen [::]:80 default_server ipv6only=on;

   server_name server2.com;

   location / {
          proxy_pass http://server1.com:8000/app/;
  }