title: How to setup php-fpm and nginx on 2 separate containers with different volume paths
body: <p>I'm attempting to setup a development environment using docker using 2 containers: <code>nginx</code> and <code>php7-fpm</code>.</p>
  
  <p>What I want to happen is when a user visits any URL that contains <code>/api</code> it uses php-fpm, but everything else is loaded from <code>/var/www/html</code>.</p>
  
  <p>Here is my configuration:</p>
  
  <p><strong>site.conf:</strong></p>
  
  <pre><code>server {
      index index.html;
      server_name impressive.local;
      error_log  /var/log/nginx/error.log;
      access_log /var/log/nginx/access.log;
      root /var/www/html;
  
      location /api {
          index index.php;
          alias /var/www/api;
  
          location ~ \.php$ {
              try_files $uri =404;
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass php:9000;
              fastcgi_index index.php;
              include fastcgi_params;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              fastcgi_param PATH_INFO $fastcgi_path_info;
          }
      }
  }
  </code></pre>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>web:
    image: nginx
    volumes:
      - ./frontend/public:/var/www/html
      - ./site.conf:/etc/nginx/conf.d/site.conf
    links: [ php ]
    ports:
      - "8080:80"
    environment:
      - NGINX_HOST=http://impressive.local
      - NGINX_PORT=80
  
  php:
      image: php:7-fpm
      volumes:
      - ./api:/var/www/api
  </code></pre>
  
  <p>This doesn't work as expected and when I visit <code>impressive.local/api</code> I get the following error in logs:</p>
  
  <pre><code>web_1  | 2019/01/10 12:23:47 [error] 6#6: *1 "/var/www/api/index.php" is not found (2: No such file or directory), client: 172.17.0.1, server: impressive.local, request: "GET /api/ HTTP/1.1", host: "impressive.local:8080"
  </code></pre>
  
  <p>I realize that the php-fpm container is the one that contains the <code>/var/www/api</code> directory and not nginx. With my configuration nginx is trying to <code>alias</code> to a non existent path and is thus failing.</p>
  
  <p>My question is how is possible to achieve this?</p>