0

如何为 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-apacheFROM php:7.4.4-fpm删除。但现在?现在不需要 PHP 和 NGinx 的特定配置。EXPOSECOMMAND

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

4

2 回答 2

0

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;
    }
}
于 2021-03-25T15:41:09.307 回答
0

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

PHP 容器:

从 php:7.4-fpm ...

Nginx 容器:

FROM 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; 在以下代码段中,都将其安装为只读;如果你需要写,然后相应地改变。

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"
于 2021-03-09T08:52:39.973 回答