Docker-compose Nginx php-fpm file not found Docker-compose Nginx php-fpm file not found nginx nginx

Docker-compose Nginx php-fpm file not found


Here is how you can find the problem

  1. Switch on the nginx debug mode with custom command, eg:

docker-compose.yml

web:    image: nginx    volumes:        - "~/www/project:/var/www"        - "~/www/project/vhost.conf:/etc/nginx/conf.d/site.conf"    # Add this row:    command: [nginx-debug, '-g', 'daemon off;']
  1. Edit your "site.conf" file (in this example it is the ~/www/project/vhost.conf file) Switch on the debug mode by the error_log (add "debug" word at the end):
error_log "/var/log/nginx/error.log" debug;
  1. (Re)start the "web" container:
docker-compose stop webdocker-compose up -d web
  1. Test the containers, are all containers running?
docker-compose ps
  1. Test in browser
  2. "Connect" and view or download ( http://blog.dcycle.com/blog/ae67284c/docker-compose-cp ) and view the /var/log/nginx/error.log file.

The problem in the most of case

You haven't set yet or you are using different directory structure in web and php-fpm. If you want to use different structure than you have to set the "fpm structure" at the fastcgi_param SCRIPT_FILENAME place, like this:

If your docker-compose.yml contains like this:

phpfpm:    image: php:fpm    volumes:        - "~/www/project:/var/www/html/user/project"#                        ^^^^^^^^^^^^^^^^^^^^^^^^^^ the path in the php-fpm container

You have to set this in "site.conf" in nginx container:

fastcgi_param SCRIPT_FILENAME /var/www/html/user/project$fastcgi_script_name;#                             ^^^^^^^^^^^^^^^^^^^^^^^^^^


Finally found it:

I was missing this line in the volume of PHP section of docker-compose:

"./html:/usr/share/nginx/html"

here's what the docker-compose should look like:

project3-front:    image: nginx    ports:        - "80:80"    links:        - "project3-php:project3-php"    volumes:        - ".:/home/docker"        - "./nginxdir/default.conf:/etc/nginx/conf.d/default.conf"        - "./html:/usr/share/nginx/html"project3-php:    build: phpdir    volumes:        - ".:/home/docker:rw"        - "./html:/var/www/html"    ports:        - "9000:9000"    working_dir: "/home/docker"

The absolute root (here "/usr/share/nginx/html") in the nginx default.conf file had to be set as well in the php part of docker-compose (was only under nginx before)

That's a relief ;)


In my case the volumes: of php and nginx were pointing a the correct (and hence the same) directory. But in my nginx config there was a NGINX_SERVER_ROOT: pointing the wrong way.

So make sure you double check all volumes and root directory settings. Some are easy to overlook.