Docker-compose nginx php-fpm file not found

I have a simple docker-compose configuration with php-fpm and nginx and I don't see any php file. When I go to localhost, it shows "File not found."

I tried everything I could find on the net, but everything I tried failed. It works fine for html, but not for php files. It seems to be a problem with the path or something like that.

I encounter this error when I docker-compose logs :

 project3-php_1 | 172.17.0.5 - 29/Mar/2016:13:29:12 +0000 "GET /index.php" 404 project3-front_1 | 172.17.0.1 - - [29/Mar/2016:13:29:12 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36" project3-front_1 | 2016/03/29 13:29:12 [error] 8#8: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.2:9000", host: "localhost" 

Here is my docker-compose:

 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" 

Then my docker file for php:

 FROM php:5.6-fpm EXPOSE 9000 

my default.conf for nginx:

 server { listen 80; server_name localhost; index index.php index.html; error_log /var/log/nginx/error.log warn; access_log /var/log/nginx/access.log; root /usr/share/nginx/html; location ~ \.php$ { fastcgi_pass project3-php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } 

pwd main folder:

 /media/revenge/share/PROJECTS/docker_images/php7-nginx 

File hierarchy:

 β”œβ”€β”€ docker-compose.yml β”œβ”€β”€ html β”‚  β”œβ”€β”€ index.php β”œβ”€β”€ nginxdir β”‚  β”œβ”€β”€ default.conf β”œβ”€β”€ phpdir β”‚  β”œβ”€β”€ dockerfile β”‚  └── php.ini 

The whole chmod 777 folder

Any idea would be greatly appreciated. I am sure that I did not receive something. Thanks in advance.

+5
source share
3 answers

Finally found:

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

"./HTML:/USR/parts/Nginx/html"

Here's what the docker 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 should also be installed in the php part of docker-compose (previously there was only nginx)

This is a relief;)

+1
source

Here is how you can find the problem

  • Turn on nginx debugging mode with custom command , for example:

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 the site.conf file (in this example, the file ~/www/project/vhost.conf ). Turn on the error_log debugging mode (add the word "debugging" at the end):
 error_log "/var/log/nginx/error.log" debug; 
  1. (Re) run the web container:
 docker-compose stop web docker-compose up -d web 
  1. Check containers, all containers work?
 docker-compose ps 
  1. Test in browser
  2. Connect and browse or download ( http://blog.dcycle.com/blog/ae67284c/docker-compose-cp ) and browse the /var/log/nginx/error.log file.

Problem in most cases

You have not yet installed or are using a different directory structure in "web" and "php-fpm". If you want to use a different structure than you need to set the "fpm structure" in the place of fastcgi_param SCRIPT_FILENAME , for example:

Docker-compose.yml

 phpfpm: image: php:fpm volumes: - "~/www/project:/var/www/html/user/project" 

"site.conf"

 fastcgi_param SCRIPT_FILENAME /var/www/html/user/project$fastcgi_script_name; 
0
source

In my case, the volumes: from php and nginx pointed to the correct (and therefore the same) directory. But NGINX_SERVER_ROOT appeared in my nginx configuration: indicating the wrong path.

Therefore, make sure that you double-check all volumes and root settings. Some are easy to overlook.

0
source

Source: https://habr.com/ru/post/1245994/


All Articles