我想在机器上用docker设置一个完整的LNMP环境。但是分离的php fpm有一些问题
我所做的是:
>
从docker.io拉取图像:
docker pull php:7.1-fpm
docker pull nginx
运行图像:
docker run-d——名称php fpm-v/data/docker/php fpm/configs/:/usr/local/etc/php fpm。d-v/data/Docker/nginx/html:/var/www/html-php:7.1-fpm
docker run-d——名称nginx-v/data/docker/nginx/configs/:/etc/nginx-v/data/docker/nginx/html:/var/www/html-p 80:80——链接php fpm nginx
所有目录
配置文件如下:
nginx.conf
server {
listen 80 default_server;
server_name SkyEyeLab;
root /var/www/html;
fastcgi_read_timeout 90;
location ~ \.php {
fastcgi_pass php-fpm:9000;
}
}
和php-fpm.conf
(一些重要的配置部分):
listen 0.0.0.0:9000
listen.allowed_clients = any
然后我查了一下nginx的环境
[root@w-Lab01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6faf4a4b4f7e nginx "nginx -g 'daemon off" 19 minutes ago Up 19 minutes 0.0.0.0:80->80/tcp, 443/tcp nginx
9a6caff831d3 php:7.1-fpm "php-fpm" 20 minutes ago Up 20 minutes 9000/tcp php-fpm
[root@w-Lab01 ~]# docker exec 6faf4a4b4f7e ping -c3 php-fpm
PING php-fpm (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: icmp_seq=0 ttl=64 time=0.081 ms
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.041 ms
--- php-fpm ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.018/0.047/0.081/0.026 ms
[root@w-Lab01 ~]# docker exec 9a6caff831d3 ss -apn
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 *:9000 *:* users:(("php-fpm",pid=1,fd=7))
一切似乎都很好。然后,我在/data/Docker/nginx/html下创建了一个.php(它被安装到nginx的/var/www/html目录),包含以下内容:
<?php
phpinfo();
?>
然后访问http://localhost:80/a.php在web浏览器中。但我只有一个空页面,我检查了访问权限。nginx的日志:
[root@w-Lab01 ~]# docker logs 6faf4a4b4f7e
220.181.171.120 - - [11/Oct/2016:10:25:11 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
220.181.171.120 - - [11/Oct/2016:10:25:12 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
220.181.171.120 - - [11/Oct/2016:10:31:58 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
220.181.171.120 - - [11/Oct/2016:10:31:59 +0000] "GET /a.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"
看来a.php
的解析是正确的
也许,如果您想在nginx conf中使用名称“php fpm”,您需要像这样链接容器:
docker run -d --name php-fpm -v /data/Docker/php-fpm/configs/:/usr/local/etc/php-fpm.d -v /data/Docker/nginx/html:/var/www/html php:7.1-fpm
及之后:
docker run -d --name nginx --link php-fpm:php-fpm -v /data/Docker/nginx/configs/:/etc/nginx -v /data/Docker/nginx/html:/var/www/html -p 80:80 --link php-fpm nginx
嗯,在我更改了nginx的配置文件之后:
server {
listen 80 default_server;
server_name SkyEyeLab;
root /var/www/html;
fastcgi_read_timeout 90;
location ~ \.php {
fastcgi_pass php-fpm:9000;
}
}
到
server {
listen 80 default_server;
server_name SkyEyeLab;
root /var/www/html;
fastcgi_read_timeout 90;
location ~ \.php {
fastcgi_pass php-fpm:9000;
include fastcgi.conf;
}
}
一切都很好。
fastcgi.conf是环境配置文件。你可以检查你的nginx的配置目录下(通常 /etc/nginx),看看是否有fastcgi.conf或fastcgi_param。