【问题标题】:devspace: from unique deployment PHP:apache to PHP-FPM + Nginxdevspace:从独特的部署 PHP:apache 到 PHP-FPM + Nginx
【发布时间】:2021-06-05 21:04:22
【问题描述】:

如何为 devspace 进行 PHPFPM+Nginx 部署?

实际上,我正在使用 PHP-Apache 并拥有这个 devspace.yaml

[...]
deployments:
- name: panel
  helm:
    componentChart: true
    values:
      containers:
      - image: registry.digitalocean.com/mycompany/myapp
      service:
        ports:
        - port: 80
      ingress:
        rules:
        - host: "mydomain.com.ar"

我的 Dockerfile 是这样的

FROM php:7.4.4-apache
[...]
EXPOSE 80
CMD ["apache2-foreground"]

一切正常,主机已在 Ingress 上注册。但是,我喜欢从 PHPApache 升级到 PHP-FPM + Nginx。

我将我的 Dockerfile 从 FROM php:7.4.4-apache 更改为 FROM php:7.4.4-fpm 并删除了 EXPOSECOMMAND。但现在?现在不需要 PHP 和 NGinx 的特定配置。

那么,如何将 nginx 服务添加到devspace.yaml 并连接到 php-fpm?

【问题讨论】:

    标签: php docker nginx kubernetes devspace


    【解决方案1】:

    您可以在一个 pod 中使用两个容器,一个用于 PHP-FPM,一个用于 Nginx。 这样(因为它们在同一个 pod 中),它们可以通过端口 9000 轻松通信。

    PHP 容器:

    来自 php:7.4-fpm ...

    Nginx 容器:

    来自 nginx:1.9-alpine ...

    确保在 Nginx 配置中包含 FPM:

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

    在“devspace.yaml”配置中,您将在 images 节下列出它们。

    您可以将网站数据挂载到两个容器中;请注意,您不能拥有多个 readOnly: false volume mount;在下面的 sn-p 中,都将其挂载为只读;如果你需要写,那就相应地改变。

    deployments:
    - name: my-component
      helm:
        componentChart: true
        values:
          containers:
          - name: nginx
            image: "nginx:1.9-alpine"
            volumeMounts:
            - containerPath: /var/www/html
              volume:
                name: website-data
                subPath: /website-data
                readOnly: true
          - name: php-fpm
            image: "php:7.4-fpm"
            volumeMounts:
            - containerPath: /var/www/html
              volume:
                name: website-data
                subPath: /website-data
                readOnly: true
          volumes:
          - name: website-data
            size: "5Gi"
    

    【讨论】:

    • 谢谢!你有 devspace.yaml 的例子吗?我需要有关此 yaml 文件的帮助。我对 nginx 或 php-fpm 的配置没有任何问题。欢迎任何例子。如果您添加示例,我如何在两个图像上共享相同的代码,太好了!
    【解决方案2】:

    devspace.yaml:

    version: v1beta9
    images:
      app-nginx:
        image: registry.digitalocean.com/reyesoft/app-nginx
        dockerfile: build/nginx/Dockerfile
        # preferSyncOverRebuild: true
        preferSyncOverRebuild: true
        appendDockerfileInstructions:
          - USER root
      app-php:
        image: registry.digitalocean.com/reyesoft/app-php
        dockerfile: build/php/Dockerfile
        preferSyncOverRebuild: true
        injectRestartHelper: true
        appendDockerfileInstructions:
        - USER root
    deployments:
    - name: app
      helm:
        componentChart: true
        values:
          containers:
          - name: app-nginx
            image: registry.digitalocean.com/reyesoft/app-nginx
          - name: panel
            image: registry.digitalocean.com/reyesoft/app-php
            env: &panelEnv
              - name: APP_ENV
                value: "develop"
          service:
            ports:
              - port: 80
          ingress:
            # tls: true
            rules:
              - host: "reyesoft.com"
    [...]
    

    nginx.conf:

    server {
    
        # [...]
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            root           /usr/share/nginx/html/public/;
    
            include php_location.include/*.conf;
    
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            # fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
            fastcgi_param   SCRIPT_FILENAME         $fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 2016-05-25
      • 2020-05-08
      • 1970-01-01
      • 2020-08-08
      • 2015-05-19
      • 1970-01-01
      • 2014-08-04
      相关资源
      最近更新 更多