首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kubernetes nginx php部署

Kubernetes nginx php部署
EN

Stack Overflow用户
提问于 2018-09-01 21:07:42
回答 1查看 1.9K关注 0票数 2

我需要一些关于nginx应用程序部署的帮助。我对试图运行php代码的kubernetes完全陌生。我在迷你库上运行这个。

这是我的Dockerfile文件

代码语言:javascript
复制
FROM php:7.2-fpm
RUN mkdir /app
COPY hello.php /app

这是我的web.yaml文件,包括部署和服务

代码语言:javascript
复制
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: web-deployment
  labels:
    app: web-server
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: web-server
    spec:
      volumes:
    # Create the shared files volume to be used in both pods
        - name: shared-files
          emptyDir: {}


        - name: nginx-config-volume
          configMap:
            name: nginx-config
      containers:
      - name: nginx
        image: nginx:latest
        ports:
          - containerPort: 80
        volumeMounts:
        - name: shared-files
          mountPath: /var/www/html
        - name: nginx-config-volume
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
      - name: php-fpm
        image: my-php-app:1.0.0
        ports:
          - containerPort: 80
        volumeMounts:
        - name: shared-files
          mountPath: /var/www/html
        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh", "-c", "cp -r /app/. /var/www/html"]
---
apiVersion: v1
kind: Service
metadata:
  name: web-service
  labels:
    app: web-server
spec:
  ports:
  - port: 80
  type: NodePort
  selector:
    app: web-server

这是nginx ConfigMap的ConfigMap文件。

代码语言:javascript
复制
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
data:
  nginx.conf: |
    events {
    }
    http {
      server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # Set nginx to serve files from the shared volume!
        root /var/www/html;
        server_name _;
        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 127.0.0.1:9000;
        }
      }
    }

我创建了部署、服务和configmap,使用

代码语言:javascript
复制
kubectl create -f web.yaml

kubectl create -f configmap.yaml

在我通过ip和端口之后

代码语言:javascript
复制
minikube service web-service --url

当我浏览这个ip时,我得到了一个类似于这个http://192.168.99.100:31170的Ip,我得到了一个类似于nginx 403禁忌的响应。

我在这里做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2018-09-02 15:55:19

似乎nginx无法访问默认页面。

index hello.php添加到nginx配置中

代码语言:javascript
复制
 location / {
          index hello.php;
          try_files $uri $uri/ =404;
        }

或者,通过绝对URL http://192.168.99.100:31170/hello.php访问应用程序。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52132193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档