I’m trying to set a k8s deployment with 2 pods (nginx + php-fpm), but I can’t get php-fpm to execute the php scripts. The webpage displays File not found.
, and in logs :
- fpm pod :
192.168.3.187 - 13/Nov/2020:16:44:06 +0000 "GET /index.php" 404
- nginx pod :
2020/11/13 16:44:06 [error] 20#20: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.45, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://10.98.178.35:9000", host: "192.168.1.220"
The .html
files are served as expected.
Without the Location ~ .php$
server block of nginx I’m able to download .php
files, so the problem is really with php-fpm; when entering the container, I can see the scripts are present.
In my deployment, a PersistentVolume on an NFS is mounted on both pods, in /app
. Nginx is configured with this configMap :
default.conf: | server { listen 80 default_server; server_name _; add_header X-Backend-Server $hostname; root /app; index index.php index.html; location / { try_files $uri $uri/ =404; } location ~ .php$ { include fastcgi_params; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass phpfpm-deploy-svc.default.svc.cluster.local:9000; } }
Where phpfpm-deploy-svc.default.svc.cluster.local
is the DNS resolution of the PHP-FPM service (irrelevant to paste the service code).
php-fpm is a classic deployment :
spec: containers: - name: phpfpm image: php:7.3-fpm ports: - containerPort: 9000 volumeMounts: - name: nfs-volume mountPath: /app volumes: - name: nfs-volume persistentVolumeClaim: claimName: nfs-pvc
with its own service :
apiVersion: v1 kind: Service metadata: name: phpfpm-deploy-svc spec: ports: - port: 9000 selector: app: phpfpm-deploy type: ClusterIP
Most of the solutions seen here are related to the line fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
: that’s possible, but I still has to find a working one.
Without k8s (only docker-compose), I can create this configuration witout issue.
Advertisement
Answer
Well, my code above is working fine : the NFS server was the problem, it wasn’ doing any mapping on users.
So I was able, from containers, to list the files on the NFS volume as root… but not as www-data, which is the user running php-fpm.
Setting correct mapping on the NFS volume solved it.