title: Nginx - configure location regex for all static file in sub alias
body: <p>I've been trying almost one day with no luck to configure nginx as proxy reverse for apache.
  I expect that nginx will serve all static file, and the rest is passed to apache.</p>
  
  <p>It's not hard to achieve this if the site resides on the root domain name.</p>
  
  <p>For example, I've successfully set:</p>
  
  <pre><code>www.mydomain.com
  
  location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt)$ {
       root /path/to/mysite;
  }
  
  location / {
       proxy_pass 127.0.0.1:8080;
       proxy_set_header Host $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Real-IP $remote_addr;
  }
  </code></pre>
  
  <hr>
  
  <p>now the problem arises as I want to configure site within alias
  for example:
  www.mydomain.com/site1</p>
  
  <p>Does anybody know how to achieve the same purpose?</p>
  
  <p>I tried below configuration doesn't work:</p>
  
  <pre><code>location /site1 {
      location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt)$ {
              root /path/to/anothersite1;
      }
       proxy_pass apache:8080;
       proxy_set_header Host $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Real-IP $remote_addr;
  }
  </code></pre>
  
  <p>the problem is that the 'root' directive doesn't replace the /site1 URI.
  For example, a request to</p>
  
  <pre><code>www.mydomain.com/site1/folder/pic.jpg
  </code></pre>
  
  <p>will be handled by opening file:</p>
  
  <pre><code>/path/to/anothersite1/site1/folder/pic.jpg;
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>/path/to/anothersite1/folder/pic.jpg
  </code></pre>
  
  <p>I really appreciate any help on this.
  I've tried to replace 'root' directive with 'alias' but still no luck.</p>
  
  <p>Thanks beforehand,</p>