Getting a 403 error from nginx when trying to build an nginx and php-fpm dev environment

I’m trying to get a simple nginx with php project up and running under Docker, but I’m getting a 403 error now that I’ve modified my nginx configuration to point at the php server.

My docker-compose.yaml is as follows:

version: '3.8'

# Services
services:

  # Nginx Service
  nginx:
    image: nginx:latest
    ports:
      - 8880:80
    volumes:
      - ./src:/var/www/php
      - ./nginx/conf.d:/etc/nginx/conf.d
    depends_on:
      - php

  # PHP Service
  php:
    image: php:8.1-fpm
    working_dir: /var/www/php
    volumes:
      - ./src:/var/www/php

I have a php.conf file under my ./nginx/conf.d directory as follows:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root   /var/www/php;
    index  index.php;

    location ~* .php$ {
        fastcgi_pass   php:9000;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_NAME     $fastcgi_script_name;
    }
}

and under my ./src directory I have a very simple index.php that should call phpinfo() as follows:

<?php
phpinfo():
?>

nginx itself was working fine with the default configuration and the container would serve the “Welcome to nginx!” page no problem. But with the above config to point to the php-fpm container it breaks.

The error is coming from the nginx container according to the logs:

192.168.1.162 - - [10/May/2025:23:24:02 +0000] "GET / HTTP/1.1" 403 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36" "-"
2025/05/10 23:24:02 [error] 21#21: *7 "/var/www/php/index.php" is forbidden (13: Permission denied), client: 192.168.1.162, server: , request: "GET / HTTP/1.1", host: "192.168.1.99:8880"

I have connected to both containers and have checked that index.php is both visible and readable (I can cat the file no problem from inside the container), I’ve even added other read and execute permissions to the index.php file but that makes no difference.

I guess something simple must be wrong with the php.conf as I don’t see anything in the php container’s log to say that it has received any forwarded request from the nginx container, but I am getting nowhere trying to figure out what is wrong.

Docker is running on a UGreen NAS, but this seems more fundamental than a host problem. I think I am just missing something in the setup.