一、从官方pull了nginx和php7.3;
二、直接创建镜像并复制配置文件到本地;
#类似下面这种,最终获得
cp myphp:/etc D:\docker\workspace\php\73\etc
...
#最终获得目录
#D:\docker\workspace\nginx\conf.d
#D:\docker\workspace\php\73\usr
#D:\docker\workspace\php\73\etc
三、创建容器:
#本地web目录:D:\docker\workspace\www
docker run -dit --name myphp -p 9000:9000 -v D:\docker\workspace\php\73\etc:/etc -v D:\docker\workspace\php\73\usr:/usr -v D:\docker\workspace\www:/usr/share/nginx/html phpdockerio/php73-fpm
docker run --name mynginx -p 80:80 --privileged=true -v D:\docker\workspace\www:/usr/share/nginx/html -v D:\docker\workspace\nginx\conf.d:/etc/nginx/conf.d --link myphp:php -d nginx
四、配置文件修改
- 本地新增文件:D:\docker\workspace\nginx\conf.d\mynginx.conf
#本地新增文件:D:\docker\workspace\nginx\conf.d\mynginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
# 这里改动了,也可以写你的域名
server_name localhost;
# Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 这里新加的
# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.
# Fastcgi服务器和程序(PHP,Python)沟通的协议.
location ~ \.php$ {
# 设置监听端口
fastcgi_pass php:9000;
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
}
五、访问 html、php
浏览器访问:http://localhost/index.html 没有问题,
浏览器访问:http://localhost/index.php 变成了下载index.php?
浏览器访问:http://localhost 访问的是index.html?