我有下面的docker作文.适用于本地开发的yaml文件无问题:
- Nginx容器只是运行一个指向php的upstream Web服务器
- Php只运行Php fpm+my扩展
- 我有一个外部docker同步卷,其中包含与nginx+php共享的代码库.
- 我的应用程序的全部内容纯粹是返回一组json api数据的PHP.没有静态assets资源 被提供.
version: '3.9'
networks:
backend:
driver: bridge
services:
site:
container_name: nginx
depends_on: [php]
image: my-nginx:latest
networks: [backend]
ports: ['8080:80', '8081:443']
restart: always
volumes: [code:/var/www/html:nocopy]
working_dir: /var/www/html
php:
container_name: php
image: my-php-fpm:latest
networks: [backend]
ports: ['9000:9000']
volumes: [code:/var/www/html:nocopy]
working_dir: /var/www/html
volumes:
code:
external: true
我正在研究如何在我的生产基础设施中部署它,我喜欢AWS ECS.我可以创建一个单一的任务定义,启动一个单一的服务,并定义两个容器(以及共享我在构建过程中添加的代码卷),应用程序也可以工作.
这个解决方案对我来说似乎很奇怪,因为现在我的应用程序可以扩展的唯一方法是每次给我一个{php+nginx}容器集.我的PHP需求将比我的nginx需求扩展得更快,所以这让我觉得有点浪费.
我try 了以下设置:
- 仅针对nginx的1个ECS服务
- 1个仅适用于php的不同ECS服务
- 两者都是负载平衡的,但由于使用Fargate,并且它们位于不同的服务上,我没有办法在nginx容器上添加
volumesFrom
块,让它能够访问我的代码(在构建过程中,我在PHP容器上打包了代码).我无法引用PHP docker容器来实现这一点.
我的配置"有效",因为负载平衡的Nginx服务现在可以独立于负载平衡的PHP服务进行扩展.他们都能互相交谈.但Nginx没有我的代码意味着它不得不在我希望我的phpupstream 处理的任何事情上返回404.
server {
listen 80;
server_name localhost;
root /var/www/html/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /health {
access_log off;
return 200 'PASS';
add_header Content-Type text/plain;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app-upstream;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
proxy_http_version 1.1;
proxy_set_header "Connection" "";
}
}
是否有任何我可以编写的nginx配置可以让这个设置(nginx无法访问我的代码)正常工作?
感觉我唯一的 Select 是要么将相同的代码复制到两个容器上(这感觉很奇怪),要么将它们组合到同一个容器中(这违反了1服务/1容器规则),要么接受我不能像我希望的那样独立地扩展它们(这不是世界末日).