title: Different path mapping php-fpm on nginx used for building multiple variants of same application
body: <p>In my project I need to build multiple variants of the same application. Hence I have this <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '3.7'
  services:
  
    moodle_alpine_fpm_base:
      build:
        context: ../..
        dockerfile: dockerfiles/fpm_alpine/Dockerfile_base
      image: ellakcy/moodle:alpine_fpm_base
  
    nginx:
     image: nginx:alpine
     ports:
      - "7870:7870"
      - "7871:7871"
      - "7872:7872"
     volumes:
      - '../../conf/nginx/build/nginx_latest.conf:/etc/nginx/nginx.conf:ro'
      - "mysql-www:/var/www/html/mysql"
      - "mysql-data:/var/moodledata/mysql"
      - "psql-www:/var/www/html/psql"
      - "psql-data:/var/moodledata/psql"
      - "psql-www:/var/www/html/mariadb"
      - "psql-data:/var/moodledata/mariadb"
     links:
      - 'moodle_alpine_fpm_mysql'
      - 'moodle_alpine_fpm_mariadb'
      - 'moodle_alpine_fpm_psql'
  
    #Mysql variant
    moodle_mysql_alpine_db:
      image: mysql:5.7
      environment:
        MYSQL_RANDOM_ROOT_PASSWORD: "yes"
        MYSQL_ONETIME_PASSWORD: "yes"
        MYSQL_DATABASE: "${MOODLE_DB_NAME}"
        MYSQL_USER: '${MOODLE_MYSQL_USER}'
        MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
  
    moodle_alpine_fpm_mysql:
      build:
        context: ../..
        dockerfile: dockerfiles/fpm_alpine/Dockerfile_mysql
      image: ellakcy/moodle:mysql_maria_fpm_alpine
      links:
        - "moodle_mysql_alpine_db:moodle_db"
        - "moodle_alpine_fpm_base"
      volumes:
        - "mysql-www:/var/www/html"
        - "mysql-data:/var/moodledata"
      environment:
        MOODLE_DB_HOST: "moodle_mysql_alpine_db"
        MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
        MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
        MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
        MOODLE_ADMIN: "${MOODLE_ADMIN}"
        MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
        MOODLE_URL: "http://0.0.0.0:7870"
  
    #Mariadb for demοnstration
    moodle_mariadb_alpine_db:
      image: mariadb:10.2
      environment:
        MYSQL_RANDOM_ROOT_PASSWORD: "yes"
        MYSQL_ONETIME_PASSWORD: "yes"
        MYSQL_DATABASE: "${MOODLE_DB_NAME}"
        MYSQL_USER: '${MOODLE_MYSQL_USER}'
        MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
  
    moodle_alpine_fpm_mariadb:
      image: ellakcy/moodle:mysql_maria_fpm_alpine
      links:
        - "moodle_mariadb_alpine_db:moodle_db"
        - "moodle_alpine_fpm_base"
      volumes:
        - "mariadb-www:/var/www/html"
        - "mariadb-data:/var/moodledata"
      environment:
        MOODLE_DB_HOST: "moodle_mariadb_alpine_db"
        MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
        MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
        MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
        MOODLE_ADMIN: "${MOODLE_ADMIN}"
        MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
        MOODLE_URL: "http://0.0.0.0:7871"
  
    #Postgresql
    moodle_psql_alpine_db:
      image: postgres
      environment:
        POSTGRES_DB: "${MOODLE_DB_NAME}"
        POSTGRES_USER: '${MOODLE_MYSQL_USER}'
        POSTGRES_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'
  
    moodle_alpine_fpm_psql:
      build:
        context: ../..
        dockerfile: dockerfiles/fpm_alpine/Dockerfile_postgresql
      image: ellakcy/moodle:postgresql_fpm_alpine
      links:
        - "moodle_psql_alpine_db:moodle_db"
        - "moodle_alpine_fpm_base"
      volumes:
        - "psql-www:/var/www/html"
        - "psql-data:/var/moodledata"
      environment:
        MOODLE_DB_HOST: "moodle_psql_alpine_db"
        MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
        MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
        MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
        MOODLE_ADMIN: "${MOODLE_ADMIN}"
        MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
        MOODLE_URL: "http://0.0.0.0:7072"
  
  volumes:
    mariadb-www:
    mariadb-data: 
    mysql-www: 
    mysql-data: 
    psql-www: 
    psql-data:
  </code></pre>
  
  <p>In my <code>nginx.conf</code> there is the following setting:</p>
  
  <pre><code>events {
    worker_connections  768;
  }
  
  http {
    include  /etc/nginx/mime.types;
    default_type  application/octet-stream;
  
    charset  utf-8;
  
    gzip  on;
    gzip_disable  "msie6";
    client_max_body_size 10000M;
  
    server {
      listen  7870;
      server_name  _;
      proxy_redirect    off;
  
      root  /var/www/html/mysql;
      index  index.php;
  
      location / {
        try_files  $uri $uri/ =404;
      }
  
      location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        #fastcgi_index index.php;
        include   fastcgi_params;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param DOCUMENT_ROOT   /var/www/html;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass  moodle_alpine_fpm_mysql:9000;
      }
  
      location /dataroot/ {
          internal;
          alias /var/moodledata/mysql/;
      }
    }
  
    server {
      listen  7871;
      server_name  _;
      proxy_redirect    off;
  
      root  /var/www/html/mariadb;
      index  index.php;
  
      location / {
        try_files  $uri $uri/ =404;
      }
  
      location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        #fastcgi_index index.php;
        include   fastcgi_params;
        fastcgi_param   PATH_INFO       $fastcgi_path_info;
        fastcgi_param  DOCUMENT_ROOT    /var/www/html;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass  moodle_alpine_fpm_mariadb:9000;
      }
  
      location /dataroot/ {
        internal;
        alias /var/moodledata/mariadb/; # ensure the path ends with /
      }
    }
  
    server {
      listen  7872;
      server_name  _;
      proxy_redirect    off;
  
      root  /var/www/html/psql;
      index  index.php;
  
      location / {
        try_files  $uri $uri/ =404;
      }
  
      location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        #fastcgi_index index.php;
        include   fastcgi_params;
        fastcgi_param   PATH_INFO       $fastcgi_path_info;
        fastcgi_param DOCUMENT_ROOT    /var/www/html;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass  moodle_alpine_fpm_psql:9000;
      }
  
      location /dataroot/ {
          internal;
          alias /var/moodledata/psql/; # ensure the path ends with /
      }
    }
  }
  
  </code></pre>
  
  <p>As you can see my on each container except the database ones and the <code>nginx</code> one the <code>php</code> files are located in <code>/var/www/data</code> whilst inside the <code>nginx</code> one is located in a subfolder of <code>/var/www/html</code>.</p>
  
  <p>The reason why I do that is that I make a build repository for the <code>moodle</code> as seen in <a href="https://hub.docker.com/r/ellakcy/moodle" rel="nofollow noreferrer">https://hub.docker.com/r/ellakcy/moodle</a> . Because My computer is somewhat slow on cpu power hence I wanted to have less images when I build each variant. So I thought that it would be easier if I had a single nginx image for service all the <code>php-fpm</code> variants in order to publish them.</p>
  
  <p>In my attempt though I get the following error message:</p>
  
  <pre><code>nginx_1                      | 2019/07/21 19:55:46 [error] 6#6: *6 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.22.0.1, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://172.22.0.5:9000", host: "0.0.0.0:7870"
  
  </code></pre>
  
  <p>So I wondered how I can tell the fastcgi not to "map" a path with another one?</p>