[英]php-fpm: File not found in kubernetes
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.我正在尝试使用 2 个 pod(nginx + php-fpm)设置 k8s 部署,但我无法让 php-fpm 执行 php 脚本。 The webpage displays
File not found.
网页显示
File not found.
, and in logs: ,并在日志中:
192.168.3.187 - 13/Nov/2020:16:44:06 +0000 "GET /index.php" 404
192.168.3.187 - 13/Nov/2020:16:44:06 +0000 "GET /index.php" 404
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"
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. .html
文件按预期提供。
Without the Location ~ \.php$
server block of nginx I'm able to download .php
files, so the problem is really with php-fpm;如果没有 nginx 的
Location ~ \.php$
服务器块,我可以下载.php
文件,所以问题确实出在 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
.在我的部署中,NFS 上的 PersistentVolume 挂载在两个 pod 的
/app
中。 Nginx is configured with this configMap: Nginx 配置了这个 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).其中
phpfpm-deploy-svc.default.svc.cluster.local
是PHP-FPM服务的DNS分辨率(无关贴服务代码)。
php-fpm is a classic deployment: php-fpm 是一个经典部署:
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;
这里看到的大多数解决方案都与
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.没有 k8s(只有 docker-compose),我可以创建这个配置而不会出现问题。
Well, my code above is working fine: the NFS server was the problem, it wasn' doing any mapping on users.嗯,我上面的代码工作正常:NFS 服务器是问题所在,它没有对用户进行任何映射。
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.所以我能够从容器中以 root 身份列出 NFS 卷上的文件……但不能以 www-data 的形式列出,后者是运行 php-fpm 的用户。
Setting correct mapping on the NFS volume solved it.在 NFS 卷上设置正确的映射解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.