title: nginx and php-fpm in Docker
body: <p>I am in the process of <em>Dockerising</em> my webserver/php workflow.</p>
  
  <p>But because I am on Windows, I need to use a virtual machine. I chose boot2docker which is a Tiny Core Linux running in Virtualbox and adapted for Docker.</p>
  
  <p>I selected three containers:</p>
  
  <ul>
  <li><a href="https://registry.hub.docker.com/_/nginx/" rel="nofollow">nginx</a>: the official nginx container;</li>
  <li><a href="https://registry.hub.docker.com/u/jprjr/php-fpm/" rel="nofollow">jprjr/php-fpm</a>: a php-fpm container;</li>
  <li><a href="https://registry.hub.docker.com/_/mysql/" rel="nofollow">mysql</a>: for databases.</li>
  </ul>
  
  <p>In boot2docker, <code>/www/</code> contains my web projects and <code>conf/</code>, which has the following tree:</p>
  
  <pre><code>conf
  │
  ├───fig
  │       fig.yml
  │
  └───nginx
          nginx.conf
          servers-global.conf
          servers.conf
  </code></pre>
  
  <p>Because <code>docker-compose</code> is not available for boot2docker, I must use <code>fig</code> to automate everything. Here is my <code>fig.xml</code>:</p>
  
  <pre><code>mysql:
   image: mysql
   environment:
    - MYSQL_ROOT_PASSWORD=root
   ports:
    - 3306:3306
  
  php:
   image: jprjr/php-fpm
   links:
    - mysql:mysql
   volumes:
    - /www:/srv/http:ro
   ports:
    - 9000:9000
  
  nginx:
   image: nginx
   links:
    - php:php
   volumes:
    - /www:/www:ro
   ports:
    - 80:80
   command: nginx -c /www/conf/nginx/nginx.conf
  </code></pre>
  
  <p>Here is my <code>nginx.conf</code>:</p>
  
  <pre><code>daemon off;
  
  user  nginx;
  worker_processes  1;
  
  error_log  /var/log/nginx/error.log debug;
  pid        /var/run/nginx.pid;
  
  events {
      worker_connections  1024;
  }
  
  http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;
  
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
  
      access_log  /var/log/nginx/access.log  main;
  
      sendfile        off;
  
      keepalive_timeout  65;
  
      index    index.php index.html index.htm;
  
      include /www/conf/nginx/servers.conf;
  
      autoindex on;
  }
  </code></pre>
  
  <p>And the <code>servers.conf</code>:</p>
  
  <pre><code>server {
      server_name lab.dev;
      root /www/lab/;
  
      include /www/conf/nginx/servers-global.conf;
  }
  
  # Some other servers (vhosts)
  </code></pre>
  
  <p>And the <code>servers-global.conf</code>:</p>
  
  <pre><code>listen 80;
  
  location ~* \.php$ {
      fastcgi_index   index.php;
      fastcgi_pass    php:9000;
      include         /etc/nginx/fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME     /srv/http$fastcgi_script_name;
  }
  </code></pre>
  
  <p>So the problem now (sorry for all that configuration, I believe it was needed to clearly explain the problem): If I access <code>lab.dev</code>, no problem (which shows that the host is created in Windows) but if I try to access <code>lab.dev/test_autoload/</code>, I have a <code>File not found.</code>. I know this comes from <code>php-fpm</code> not being able to access the files, and the nginx logs confirm this:</p>
  
  <pre><code>nginx_1 | 2015/05/28 14:56:02 [error] 5#5: *3 FastCGI sent in stderr:
  "Primary script unknown" while reading response header from upstream,
  client: 192.168.59.3, server: lab.dev, request: "GET /test_autoload/ HTTP/1.1",
  upstream: "fastcgi://172.17.0.120:9000", host: "lab.dev", referrer: "http://lab.dev/"
  </code></pre>
  
  <p>I know that there is a <code>index.php</code> in <code>lab/test_autoload/</code> in both containers, I have checked. In <code>nginx</code>, it is located in <code>/www/lab/test_autoload/index.php</code> and <code>/srv/http/lab/test_autoload/index.php</code> in <code>php</code>.</p>
  
  <p>I believe the problem comes from <code>root</code> and/or <code>fastcgi_param SCRIPT_FILENAME</code>, but I do not know how to solve it.</p>
  
  <p>I have tried many things, such as modifying the <code>root</code>s, using a <code>rewrite</code> rule, adding/removing some <code>/</code>s, etc, but nothing has made it change.</p>
  
  <p>Again, sorry for all this config, but I think it was needed to describe the environment I am in.</p>