通过docker compose安装wordpress:5-php7.2-fpm
我们之前测试用的镜像wordpress:5-php7.2,它自带apache,我们当时用了nginx做反向代理。由于nginx比apache更加轻量级,所以本次测试改用wordpress:5-php7.2-fpm那样做好处是,直接使用nginx容器接收80端口的请求并传递给wordpress容器的fastcgi处理,fastcgi把匹配到的php文件给9000端口的fpm进行执行。
借用Fuck PHP-FPM with FastCGI一文的图片,就很好理解这个处理过程:
首先拉取镜像:
docker pull wordpress:5-php7.2-fpm
清除之前测试的容器:
1
docker stop $(docker ps -q)
2
docker rm $(docker ps -aq)
Copied!
创建一个www.conf文件,内容如下,用于等会替换容器内默认的/usr/local/etc/php-fpm.d/www.conf
1
[www]
2
user = www-data
3
group = www-data
4
listen = 0.0.0.0:9000
5
pm = dynamic
6
pm.max_children = 5
7
pm.start_servers = 2
8
pm.min_spare_servers = 1
9
pm.max_spare_servers = 3
Copied!
修改nginx用的default.conf为如下:
1
server {
2
listen 80;
3
server_name localhost;
4
5
access_log /var/log/nginx/host.access.log main;
6
7
location / {
8
root /var/www/html;
9
index index.php index.html index.htm;
10
try_files $uri $uri/ /index.php?$args;
11
}
12
13
error_page 500 502 503 504 /50x.html;
14
location = /50x.html {
15
root /usr/share/nginx/html;
16
}
17
18
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
19
20
location ~ \.php$ {
21
fastcgi_pass wp.maxidea.com:9000;
22
fastcgi_index index.php;
23
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
24
include fastcgi_params;
25
}
26
}
Copied!
这里要注意一点,nginx容器需要访问得到wordpress-fpm容器内的/var/www/html目录的内容,所以在修改docker-compose文件时要注意把存储卷共享给两个容器一同访问。
修改docker-compose.yaml文件成如下:
1
version: '3'
2
3
services:
4
5
db:
6
image: mysql:5.7
7
container_name: db.maxidea.com
8
volumes:
9
- ./db/data/:/var/lib/mysql/
10
env_file:
11
- ./db/env.list
12
networks:
13
net2:
14
ipv4_address: 10.10.1.101
15
expose:
16
- "3306"
17
18
wp:
19
image: wordpress:5-php7.2-fpm
20
container_name: wp.maxidea.com
21
volumes:
22
- ./fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro
23
- ./wp/wwwdata:/var/www/html
24
env_file:
25
- ./wp/env.list
26
networks:
27
net2:
28
ipv4_address: 10.10.1.102
29
expose:
30
- "9000"
31
extra_hosts:
32
- "db.maxidea.com:10.10.1.101"
33
- "nx.maxidea.com:10.10.1.103"
34
35
nginx:
36
image: nginx:alpine
37
container_name: nx.maxidea.com
38
volumes:
39
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
40
- ./wp/wwwdata:/var/www/html
41
networks:
42
net2:
43
ipv4_address: 10.10.1.103
44
expose:
45
- "80"
46
ports:
47
- "80:80"
48
extra_hosts:
49
- "db.maxidea.com:10.10.1.101"
50
- "wp.maxidea.com:10.10.1.102"
51
52
networks:
53
net2:
54
ipam:
55
driver: default
56
config:
57
- subnet: "10.10.1.0/24"
Copied!
Copy link