这里我们使用 docker-compose
我们需要先安装一个nginx并拷贝他的配置文件
docker run -itd --name nginx -p 80:80 nginx
创建目录
mkdir -p /opt/nginx/conf /opt/nginx/logs /opt/nginx/www
拷贝配置文件
docker cp nginx:/etc/nginx /opt/nginx/conf
然后停止并删除nginx容器
docker stop nginx
docker rm nginx
首先我们 编写 docker-compose.yml,内容如下
version: "2.1"
services:
nginx:
container_name: nginx
image: nginx
ports:
- "81:80"
volumes:
- /opt/nginx/www:/usr/share/nginx/html
- /opt/nginx/conf:/etc/nginx
- /opt/nginx/logs:/var/log/nginx
networks:
- lnmp-network
php:
container_name: php
image: php:5.6-fpm-alpine3.8
volumes:
- /opt/nginx/www:/www
networks:
- lnmp-network
mysql:
container_name: mysql
image: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
networks:
- lnmp-network
networks:
lnmp-network:
配置 nginx
vim /opt/nginx/conf/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /501x.html {
return 200 "1221";
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}
~
运行 docker-compose.yml
docker-compose up -d
编写 index.php 文件
vim /opt/nginx/www/index.php
内容如下
<?php
phpinfo();
?>
然后访问
http://192.168.31.147:81/index.php
就可以看到PHP经典首页了
最后修改于 2021-11-15 11:23:12
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

