Docker architecture for hosting a PHP website

I studied Docker and how I could host multiple websites on the Docker server. As I understand it, ideally, everything should work under its own containers, and these containers should not be shared.

My question is whether the overview below is a valid installation of a container with requests included in a single reverse proxy server that sends requests to the underlying web servers to handle the actual requests.

In addition, in the three situations below, I described in detail how to include source files for the application and would like to know which of the three is the most common / best to use.

My desire is to be able to run different sites on the same server in Docker. Websites may have different requirements, as illustrated by the different versions of PHP-FPM in the diagram. The deployment of the website itself is a little incomprehensible to me, as I am not sure whether to include the source files with nginx / PHP-FPM or deploy it separately.

Docker Architecture Overview

My current setup is as follows:

docker-compose.yml

version: '2' services: nginx: image: nginx:alpine restart: always ports: - '80:80' links: - example_com - example_org - example_net volumes: - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro example_com: image: php:7.0-fpm-alpine restart: always volumes: - ./sites/example_com:/var/www/example_com:ro example_org: image: php:7.0-fpm-alpine restart: always volumes: - ./sites/example_org:/var/www/example_org:ro example_net: image: php:7.0-fpm-alpine restart: always volumes: - ./sites/example_net:/var/www/example_net 

Nginx / conf.d / default.conf

 server { listen 80; server_name www.example.com example.com; location ~ \.php$ { fastcgi_pass example_com:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/example_com$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name www.example.org example.org; location ~ \.php$ { fastcgi_pass example_org:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/example_org$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name www.example.net example.net; location ~ \.php$ { fastcgi_pass example_net:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/example_net$fastcgi_script_name; include fastcgi_params; } } 

This is not shown in the above review, but the situation in the review is an ideal situation for me.

How can I configure this setting using a reverse proxy server and different PHP-FPM containers, and how can I deploy my sites and their subsequent updates?

Any input on this subject would be greatly appreciated!

+5
source share
2 answers

I think the three nginx servers connected to the main nginx server are not needed. The php-fpm process listens on a socket so you can connect directly to each php-fpm process from the main nginx server.

0
source

I have an almost similar scenario in which only one web server is running. First of all, I think that you are configured like this, using one container as a reverse proxy and another for each web server.

I'm not sure if you need to run PHP in your container. I use Apache instead of nginx (haters will hate) and created my own image for both giving me the following docker-compose.yml

 version: '2' services: webproxy: image: myown/webproxy:xy [...] webserver: image: myown/webserver:xy [...] 

Regarding your second question: I myself was on this question, and I never saw the point in using data containers. The data uses the same disk space, but you do not know where it is stored. In my opinion, it’s a little difficult to make backups. This is the reason why I use your first approach to install data volumes on the main drive.

0
source

Source: https://habr.com/ru/post/1257990/


All Articles