I'm struggling to understand where my error is. I've looked at various answers and tried the remedies, only to find that their solutions did not rectify my problem. I've stripped everything down to the VERY basics to see if I can just get a basic PHP index.php to present itself.
Here is what I'm trying to accomplish at the core:
I have docker-compose standing up 1 network, and 2 services connected to the network. One service is PHP-FPM, and the other is nginx to serve the PHP-FPM. Every time I stand this up, no matter how I seem to configure it, I just get a 502 Bad Gateway, and when I inspect the nginx container logs, I get [error] 29#29: *1 connect() failed (113: Host is unreachable) while connecting to upstream.
./docker-compose.yml
version: "3.7" networks: app: driver: bridge services: php: image: php:7.4-fpm container_name: php volumes: - /home/admin/dev/test/php/www.conf:/usr/local/etc/php-fpm.d/www.conf - /home/admin/dev/test/src/:/var/www/html networks: - app nginx: image: nginx:alpine container_name: nginx depends_on: - php ports: - "80:80" - "443:443" volumes: - /home/admin/dev/test/src/:/usr/share/nginx/html - /home/admin/dev/test/nginx/conf.d/app.conf:/etc/nginx/conf.d/app.conf networks: - app ./php/www.conf -> /usr/local/etc/php-fpm.d/www.conf
[www] user = www-data group = www-data listen = 0.0.0.0:9000 pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 ./nginx/conf.d/app.conf -> /etc/nginx/conf.d/app.conf
server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ./src/index.php -> (php)/var/www/html && (nginx)/usr/share/nginx/html (just for reference)
<?php phpinfo(); Docker: Docker version 19.03.12, build 48a66213fe Docker-compose: docker-compose version 1.25.4, build unknown Environment: Linux localhost.localdomain 5.7.14-200.fc32.x86_64 #1 SMP Fri Aug 7 23:16:37 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux (Fedora 32 Workstation)
I believe I just have a major misunderstanding of PHP-FPM but maybe there is something else.
Update During Troubleshooting The thought occurred that my overall environment (i.e. Fedora 32) was messing it up. Fedora 32 is not supported out of the box for Docker (had to change the repo settings in /etc/yum.repos.d to get it to work - had to use Fedora 31's repo). So I decided to spin up an Ubuntu 20.0.4 VM and test it there. Now the PHP-FPM and Nginx are talking; I get responses from the PHP-FPM container! However, now even with just the basic script, I'm getting 404 errors, but that is MUCH closer to where I need to be... now to fix the 404.
The exact error is: [error] 30#30: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream