You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac M2 Minikube环境部署NGINX+PHP-FPM遇加载异常求助

M2 Mac + Minikube + Docker环境下NGINX+PHP-FPM部署异常问题

在搭载M2芯片的Mac设备上,通过Docker运行Minikube,多次尝试在Kubernetes中部署NGINX与PHP-FPM,但始终未能成功。所有Pod均显示正常运行,但访问NGINX的NodePort时,页面一直处于加载状态。

部署所用配置

1. NGINX Helm部署命令

helm install  my-release oci://registry-1.docker.io/bitnamicharts/nginx --values nginx-values.yaml

2. nginx-values.yaml配置文件

service:
  type: NodePort

extraVolumes:
  - name: contents
    configMap:
      name: index
      items:
        - key: index.php
          path: index.php

  - name: nginx-config
    configMap:
      name: nginx
      

extraVolumeMounts:
  - name: nginx-config
    mountPath: /etc/nginx/conf.d/default.conf
    subPath: nginx.conf
  - mountPath: /var/www/html/
    name: contents

3. index ConfigMap内容(index.php文件)

<html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <?php echo '<h1>Hello World</h1>'; ?>
        <?php phpinfo(); ?>
    </body>
</html>

4. nginx ConfigMap内容(NGINX配置文件)

server {
  listen 80;
  listen [::]:80;
  access_log off;
  root /var/www/html;
  index index.php;
  server_name example.com;
  server_tokens off;
  location / {
    # 优先尝试返回请求对应的文件,其次是目录,最后返回404
    try_files $uri $uri/ /index.php?$args;
  }
  # 将PHP脚本转发到监听9000端口的FastCGI服务器
  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
      
    # 此处修改为服务名称
    fastcgi_pass phpfpm:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  }
}

5. PHP-FPM部署文件

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpfpm
  labels:
    app: phpfpm
    layer: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: phpfpm
  template:
    metadata:
      labels:
        app: phpfpm   
    spec:
      containers:
        - name: phpfpm
          image: arm64v8/php:fpm-alpine # 原镜像为php:fpm-alpine 
          ports:
            - containerPort: 9000
          volumeMounts:
            - mountPath: /var/www/html/
              name: contents
      volumes:
        - name: contents
          configMap:
            name: index
            items:
              - key: index.php
                path: index.php

---
kind: Service 
apiVersion: v1 
metadata:
  name: phpfpm
  labels:
    app: phpfpm
    layer: backend   
spec:
  type: ClusterIP
  selector:
    app: phpfpm
  ports:
    - port: 9000
      targetPort: 9000

内容的提问来源于stack exchange,提问作者Zexxxx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 18:05:36