CenterOS docker 下简单部署 PHP+Nginx
安装nginx
1.获取最新官方镜像
docker pull nginx:latest
2.运行容器
- –name nginx-test:容器名称。
- -p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。
- -d nginx: 设置容器在在后台一直运行。
docker run --name nginx -p 8080:80 -d nginx
3.安装成功,进行访问 127.0.0.1:8080/
安装php
1.拉取官方的镜像【7.3】
docker pull php:7.3-fpm
- 运行容器
docker run --name php7 -v ~/nginx/www:/www -d php:7.3-fpm
3.创建 ~/nginx/conf/conf.d 目录:
mkdir -p ~/nginx/conf/conf.d
4.在该目录下添加 ~/nginx/conf/conf.d/runoob-test-php.conf 文件
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}
5.启动nginx
docker run --name php-nginx -p 80:80 -d -v ~/nginx/www:/usr/share/nginx/html:ro -v ~/nginx/conf/conf.d:/etc/nginx/conf.d:ro --link php7:php nginx
6.接下来我们在 ~/nginx/www 目录下创建 index.php
<?php
echo phpinfo();
?>
7.进行访问 127.0.0.1/
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: