最近用 docker 来搭建 nginx + php-fpm 服务器,参考网上的教程后发现了一个不太明白的地方。Docker-compose.yml 文件如下:
version: '3'
services:
openresty:
image: openresty/openresty:alpine
network_mode: "host"
volumes:
- ./:/home
command: openresty -p /home -c conf/nginx.conf -g "daemon off;"
restart: always
php73-fpm:
image: php:7.3-rc-fpm-alpine
network_mode: "host"
volumes:
- ./:/home
restart: always
疑惑点:php73-fpm 容器下必须挂载 openresty 挂载过的文件卷?
带着疑问,在 google 上找到了答案。
Nginx 与 php-fpm 通信过程是通过 nginx 的 fastcgi 模块来处理的,即 fastcgi 模块将来自客户端的关于 php 文件的请求转发给 php-fpm 来处理。既然是转发请求,那么必须要遵循一定的协议,也就是 fastcgi.conf 所规定的协议了。
nginx.conf 中配置处理 php 文件的 location 规则如下:
server {
listen 80;
location ~ \.php$ {
root /home