简体   繁体   English

Apache使用不同的Php-Fpm容器

[英]Different Php-Fpm containers with Apache

my production server is running Docker with a classic structure Db-Container, Server-Container and Php-Fpm container. 我的生产服务器正在运行具有经典结构Db-Container,Server-Container和Php-Fpm容器的Docker。

What i would like to do is to split the sources in order to have different containers for the 3 main parts of the project. 我想做的是拆分源,以便为项目的3个主要部分使用不同的容器。 Now they work the old way like mydomain.com/index for the main site, mydomain.com/api and mydomain.com/adm for other services. 现在,它们以旧的方式工作,例如主站点使用mydomain.com/index,其他服务使用mydomain.com/api和mydomain.com/adm。

How i have to setup the Apache virtual host in order to map requests like this? 我如何设置Apache虚拟主机才能映射这样的请求?

mydomain.com -> fcgi://siteFpm:9000
mydomain.com/api -> fcgi://apiFpm:9000
mydomain.com/cms -> fcgi://cmsFpm:9000

Thanks 谢谢

Use docker-compose expose and FastCgiExternalServer in conf file or vhosts file 在conf文件或vhosts文件中使用docker-compose暴露和FastCgiExternalServer

(Note this is an approach I will be taking and am still researching. I will update as I know more. But it should hopefully give you an outline of what to do too. I do update my answers, not an empty promise, see this example here: Getting a LAMP stack running on a Vagrant VM (under windows 7 host), full instructions? ) (请注意,这是我将要采用并且仍在研究中的一种方法。随着我所知,我将进行更新。但是它也应该给您概述该怎么做。此处的示例: 获取在Vagrant VM(在Windows 7主机下)上运行的LAMP堆栈,是否有完整说明?

Install docker-compose which provides an official standardised way to batch/automate running of your docker containers, using a docker-compose.yml file, rather than using the command line docker command to start up each command individually. 安装搬运工,撰写它提供了一个正式的标准化的方法来批量/自动化您泊坞窗容器运行,使用docker-compose.yml文件,而不是使用命令行docker命令单独启动每个命令。

In the docker-compose.yml file, define your php-fpm service, eg: docker-compose.yml文件中,定义您的php-fpm服务,例如:

services: 服务:

use the EXPOSE keyword statement/instruction to make available the port of your php-fpm to apache. 使用EXPOSE关键字语句/指令使php-fpm的端口可用于apache。

An example of expose is shown in this article: Multiple versions of AMP in One Host where in the example docker-compose.yml contains this expose statement: 本文显示了expose的示例: 一台主机中的多个版本的AMP,其中示例docker-compose.yml包含以下暴露语句:

  expose:      
   - "3306"   

- which enables the sql database to be available to other docker containers. -使sql数据库可用于其他docker容器。

You will also need to ensure that the php files are available to both php and apache containers - CREDIT: https://stackoverflow.com/a/40449377/227926 您还需要确保php和apache容器都可以使用php文件-CREDIT: https : //stackoverflow.com/a/40449377/227926

Then, that same expose: port, together with the service name will need to be referenced from the Apache FastCgiExternalServer directive in the vhosts file or conf file. 然后,将需要从vhosts文件或conf文件中的Apache FastCgiExternalServer伪指令中引用相同的expose:端口以及服务名称。 Choosing a vhosts file or conf file to put the directive in is, I think, what seems to be a personal preference though research may reveal differences where one or the other suits your circumstance more. 我认为,选择一个vhosts文件或conf文件放入该指令似乎是个人喜好,尽管研究可能会揭示出差异,其中一个或另一个更适合您的情况。

An example in the conf file would look something like: conf文件中的示例如下所示:

FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization

What conf file should I put this in? 我应该把它放在哪个conf文件中?

Answer: there are several options (as indicated above), in a little more detail these are (assuming Ubunut/Debian Linux is the OS that Apache is running on top of): - httpd.conf - 000-default.conf (the default vhost) (in sites-available) - yoursite.conf (in sites-available) - and (eg) /etc/apache2/conf-available/php5.6-fpm.conf 答:有几个选项(如上所述),更详细一些(假设Ubunut / Debian Linux是Apache在其之上运行的操作系统):-httpd.conf-000-default.conf(默认vhost)(在可用站点中)-yoursite.conf(在可用站点中)-和(例如)/etc/apache2/conf-available/php5.6-fpm.conf

Where would these conf files be located? 这些conf文件将位于何处?

Answer: inside your apache docker container. 答:在您的apache docker容器中。 You will need to use the docker-compose.yml file to add (inject) the setup described into the container, once you have defined the services. 定义服务后,您将需要使用docker-compose.yml文件将描述的设置添加(注入)到容器中。 You can execute, from the docket-compose.yml the standard linux commands to insert text into config files. 您可以从docket-compose.yml执行标准linux命令,以将文本插入配置文件。

You should automate the adding of these settings rather than go in an manually edit Apache config files inside the container, because: 1) automate means that the setup is repeatable and can therefore be used for different platforms in the development workflow: dev, qa, uat, live/prod 2) no manual work required 3) Docker containers are intended to be ephemeral in that they can be destroyed and recreated. 您应该自动添加这些设置,而不要在容器内手动编辑Apache配置文件,因为:1)自动化意味着安装是可重复的,因此可以用于开发工作流程中的不同平台:dev,qa, uat,live / prod 2)无需手动操作3)Docker容器旨在临时使用,因为它们可以被销毁和重新创建。 Any persistent data should be kept outside of them - in the host -(config in Dockerfiles, docker-composer files, assets (images) in separate folders, database store outside of the container and on the host too. 任何持久性数据都应保留在它们的外部-在主机中-(在Dockerfiles中的配置,docker-composer文件,单独文件夹中的资产(图像),容器外部以及主机上的数据库存储。

Examples of FastCgiExternalServer directive: FastCgiExternalServer指令的示例:

References to Debian/Ubuntu conventions for conf files and Apache 对conf文件和Apache的Debian / Ubuntu约定的引用

Discussions about PHP-FPM - https://serverfault.com/questions/645755/differences-and-dis-advanages-between-fast-cgi-cgi-mod-php-suphp-php-fpm 关于PHP-FPM的讨论-https : //serverfault.com/questions/645755/differences-and-dis-advanages-between-fast-cgi-cgi-mod-php-suphp-php-fpm

Useful related information about docker-file.yml statements 有关docker-file.yml语句的有用的相关信息

Similar discussions on running seperate containers together 一起运行单独容器的类似讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM