docker搭建php7 && nginx
程序员文章站
2022-06-04 19:42:40
...
准备工作
创建相关目录
mkdir -p /docker/www
mkdir -p /docker/nginx/conf.d
编写nginx的default.conf
vim /docker/nginx/conf.d/default.conf
# 以下为示例内容
server {
listen 80 default_server;
server_name _;
root /usr/share/nginx/html;
location / {
index index.html index.htm index.php;
autoindex off;
}
location ~ \.php(.*)$ {
root /var/www/html/;
fastcgi_pass 172.17.0.2:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
开始部署
php
docker run -p 9000:9000 --name myphp \
-v /docker/www/:/var/www/html/ \
--privileged=true \
-d php:7.1.0-fpm
#查看php镜像的ip地址
docker inspect --format='{{.NetworkSettings.IPAddress}}' myphp
172.17.0.2
#修改default.conf配置文件,使fastcgi_pass的值为 172.17.0.2:9000
vim /docker/nginx/conf.d/default.conf
fastcgi_pass 172.17.0.2:9000;
nginx
docker run -p 80:80 --name mynginx \
-v /docker/www:/usr/share/nginx/html \
-v /docker/nginx/conf.d:/etc/nginx/conf.d \
--privileged=true \
-d nginx
测试php
echo "<?php phpinfo();" > /docker/www/info.php
访问:http:ip:port/info.php
支持mysql
docker exec -it myphp bash
docker-php-ext-install pdo_mysql mysqli
转至:https://www.jb51.net/article/113296.htm
上一篇: Nginx日志统计方案全过程
下一篇: 腌嫩姜作用有哪些,嫩姜的功效