title: Nginx reverse proxy to another nginx server serving static files
body: <p>I have an Nginx server hosting a web app which works fine when directly accessed. Its config is below</p>
  <pre><code>server {
      listen 8000 default_server;
  
      listen [::]:8000 default_server ipv6only=on;
  
      root /data/www/ ;
      server_name server1.com;
  
      location / {
          try_files $uri $uri/ =404;
      }
  
      location /app/ {
  
      }   
  }
  </code></pre>
  <p>Now i have to serve this app from another Nginx server So i setup the reverse proxy like below</p>
  <pre><code>server {
      listen 80 default_server;
  
      listen [::]:80 default_server ipv6only=on;
  
      root /data/www/ ;
      server_name server2.com;
  
      location / {
          try_files $uri $uri/ =404;
      }
  
      location /app/ {
          proxy_pass http://server1.com:8000/app/;
      }
  }   
  </code></pre>
  <p>When i access the app from server2 i am getting errors like below for example when i am accessing http: server2.com/app/css/app.css</p>
  <blockquote>
  <p>[error] 6601#0: *1 open() &quot;/data/www/app/css/app.css&quot; failed (2: No such file or directory)</p>
  </blockquote>
  <p>and no errors in serv er1 logs. Why is nginx looking for static files in server2 when i have set it to reverse proxy to server1 same setup works fine in apache with</p>
  <blockquote>
  <p>ProxyPass /app/ http:server1:8000/app/</p>
  <p>ProxyPassReverse /app/ http:server1:8000/app/</p>
  </blockquote>
  <p>What am i missing ?</p>