title: Nginx proxy_pass only works partially
body: <p>I have the following setup</p>
  
  <ul>
  <li>Master server - call it <code>https://master.com</code></li>
  <li>Slave server - call it <code>https://slave.com</code></li>
  </ul>
  
  <p>Both run Nginx on Ubuntu 16.04</p>
  
  <p>On the master server I have created the following configuration block in my <code>/etc/nginx/sites-available/default</code> file</p>
  
  <pre><code>location /test
  {
   rewrite ^/test(.*) /$1 break;
   proxy_pass https://slave.com;
   proxy_read_timeout 240;
   proxy_redirect off;
   proxy_buffering off;
   proxy_set_header Host $host;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto https;
  }
  </code></pre>
  
  <p>A <code>service nginx reload</code> later on <code>master.com</code>and I can do the following</p>
  
  <ul>
  <li>Browse to <code>https://master.com/test</code> and view the output from <code>slave.com\index.php</code>. </li>
  <li>Browse to <code>https://master.com/test/test.txt</code>and see the text in the file <code>slave.com\test.txt</code></li>
  <li>Browse to <code>https://master/com/test/test.jpg</code> and see the image in the file <code>slave.com\test.jpg</code>.</li>
  </ul>
  
  <p>However, I cannot do any of the following</p>
  
  <ul>
  <li>Browse to <code>https://master.com/test/test.php</code>which instead of showing me the output from <code>https://slave.com/test.php</code> shows me a 404 error message</li>
  <li>Browse to <code>https://master.com/test/adminer/adminer.php</code>which instead of showing me the login screen for the Adminer instance on the slave, <code>https://slave.com/adminer/adminer.php</code>shows me the login screen for the Adminer instance on <code>master.com</code>i.e. <code>https://master.com/adminer/adminer.php</code></li>
  </ul>
  
  <p>This is clearly because I am missing something in my Nginx configuration on <code>master.com</code>. However, I am unable to see what that might be.</p>
  
  <p>In the interests of completeness, here is my configuration on both servers:</p>
  
  <p><strong>Ubuntu</strong> - 16.04.3
  <strong>Nginx</strong>  - 1.10.3
  <strong>PHP</strong> - 7.0.22</p>
  
  <p>I should explain why the <code>^~</code> is required since this is not clear from my original question.  I have another block setup to handle PHP scripts on <code>master.com</code>.</p>
  
  <pre><code>location ~ \.php$ 
  {
   try_files $uri =404;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include fastcgi_params;
  }
  </code></pre>
  
  <p>Because of the way Nginx processes these directives this block takes priority when it comes to handling <code>.php</code> files and <code>master.com</code> ends up looking locally for <code>.php</code> scripts that are actually on <code>slave.com</code>. The only way to avoid this is to use <code>^~</code> </p>