devspace:从独特部署 PHP:apache 到 PHP-FPM + Nginx
devspace: from unique deployment PHP:apache to PHP-FPM + Nginx
如何为 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
并删除了 EXPOSE
和 COMMAND
。但现在?现在不需要 PHP 和 NGinx 的特定配置。
那么,如何将nginx服务添加到devspace.yaml
并连接到php-fpm?
您可以在一个 pod 中使用两个容器,一个用于 PHP-FPM,一个用于 Nginx。
这样(因为它们在同一个 pod 中),它们可以通过端口 9000 轻松通信。
PHP 容器:
从php:7.4-fpm
...
Nginx 容器:
FROM nginx:1.9-高山
...
确保在 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”配置中,您将在图像节下列出它们。
您可以将网站数据挂载到两个容器;当心,你不能有多个 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"
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;
}
}
如何为 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
并删除了 EXPOSE
和 COMMAND
。但现在?现在不需要 PHP 和 NGinx 的特定配置。
那么,如何将nginx服务添加到devspace.yaml
并连接到php-fpm?
您可以在一个 pod 中使用两个容器,一个用于 PHP-FPM,一个用于 Nginx。 这样(因为它们在同一个 pod 中),它们可以通过端口 9000 轻松通信。
PHP 容器:
从php:7.4-fpm ...
Nginx 容器:
FROM nginx:1.9-高山 ...
确保在 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”配置中,您将在图像节下列出它们。
您可以将网站数据挂载到两个容器;当心,你不能有多个 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"
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;
}
}