Apache使用不同的Php-Fpm容器 [英] Different Php-Fpm containers with Apache

查看:92
本文介绍了Apache使用不同的Php-Fpm容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的生产服务器以经典结构运行Docker Db容器,服务器容器和Php-Fpm容器.

my production server is running Docker with a classic structure Db-Container, Server-Container and Php-Fpm container.

我想做的是拆分源,以便为项目的3个主要部分使用不同的容器.现在,它们以旧方式工作,例如主站点使用mydomain.com/index,其他服务使用mydomain.com/api和mydomain.com/adm.

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. Now they work the old way like mydomain.com/index for the main site, mydomain.com/api and mydomain.com/adm for other services.

我如何设置Apache虚拟主机才能映射这样的请求?

How i have to setup the Apache virtual host in order to map requests like this?

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

谢谢

推荐答案

在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?)

安装 docker-compose ,它提供了一种正式的标准化方法来批量/自动运行您的docker容器,使用docker-compose.yml文件,而不是使用命令行docker命令单独启动每个命令.

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文件中,定义您的php-fpm服务,例如:

In the docker-compose.yml file, define your php-fpm service, e.g.:

服务:

使用EXPOSE关键字声明/说明使php-fpm的端口可用于apache.

use the EXPOSE keyword statement/instruction to make available the port of your php-fpm to apache.

本文显示了expose的示例:一个主机中的AMP的多个版本,其中示例docker-compose.yml包含以下暴露语句:

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:      
   - "3306"   

-使sql数据库可用于其他docker容器.

- which enables the sql database to be available to other docker containers.

您还需要确保php和apache容器都可以使用php文件-CR https://stackoverflow. com/a/40449377/227926

You will also need to ensure that the php files are available to both php and apache containers - CR https://stackoverflow.com/a/40449377/227926

然后,需要从vhosts文件或conf文件中的Apache FastCgiExternalServer伪指令中引用相同的expose:端口以及服务名称.我认为,选择一个vhosts文件或conf文件放入该指令似乎是个人喜好,尽管研究可能会揭示出其中一种更适合您的情况的差异.

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. 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.

conf文件中的示例如下所示:

An example in the conf file would look something like:

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

我应该把它放在哪个conf文件中?

答案:有几个选项(如上所示),更详细一些(假设Ubunut/Debian Linux是Apache在其之上运行的操作系统): -httpd.conf -000-default.conf(默认虚拟主机)(在可用站点中) -yoursite.conf(在可用站点中) -和(例如)/etc/apache2/conf-available/php5.6-fpm.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 (e.g.) /etc/apache2/conf-available/php5.6-fpm.conf

这些conf文件将位于哪里?

答案:在您的Apache docker容器内.定义服务后,您将需要使用docker-compose.yml文件将描述的设置添加(注入)到容器中.您可以从docket-compose.yml执行标准linux命令,以将文本插入配置文件.

Answer: inside your apache docker container. 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. You can execute, from the docket-compose.yml the standard linux commands to insert text into config files.

您应该自动添加这些设置,而不是在容器内手动编辑Apache配置文件,因为:1)自动化意味着安装是可重复的,因此可以在开发工作流程中用于不同平台:dev ,qa,uat,live/prod 2)无需手动操作3)Docker容器旨在成为临时容器,因为它们可以被销毁并重新创建.任何持久性数据都应保留在它们的外部-主机中((在Dockerfiles中的配置,docker-composer文件,单独文件夹中的资产(图像),容器外部以及主机上的数据库存储).

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. 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.

FastCgiExternalServer指令示例:

  • Apache 2.4 + PHP-FPM and Authorization headers
  • https://www.cyberciti.biz/tips/rhel-fedora-centos-apache2-external-php-spawn.html
  • https://www.howtoforge.com/using-php5-fpm-with-apache2-on-centos-6.2-p2
  • Difference between FastCgiExternalServer and FastCgiServer in Apache FastCGI PHP?
  • Apache 2.4.6 on Ubuntu Server: Client denied by server configuration (PHP FPM) [While loading PHP file]
  • https://www.digitalocean.com/community/questions/apache-2-4-with-php5-fpm?answer=12056
  • https://www.howtoforge.com/tutorial/apache-with-php-fpm-on-ubuntu-16-04/#-making-phpfpm-use-a-tcp-connection-optional

对conf文件和Apache的Debian/Ubuntu约定的引用

  • https://serverfault.com/questions/216252/how-to-configure-apache-sites-available-vs-httpd-conf
  • https://forum.owncloud.org/viewtopic.php?t=30157
  • https://askubuntu.com/questions/378734/how-to-configure-apache-to-run-php-as-fastcgi-on-ubuntu-12-04-via-terminal

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

有关docker-file.yml语句的有用的相关信息

  • Difference between 'image' and 'build' within docker compose
  • https://docs.docker.com/compose/compose-file/#build

关于一起运行单独容器的类似讨论

  • https://medium.com/docker-captain/multiple-versions-of-amp-in-one-host-6e107c836cd8
  • php docker link apache docker
  • Multi Docker container with PHP7 fpm and nginx
  • Docker - Run Apache on host and container for different websites
  • Linking nginx and php-fpm container together for fast interaction in docker prod
  • How to correctly link php-fpm and Nginx Docker containers?

这篇关于Apache使用不同的Php-Fpm容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆