一、docker拉取nginx和php鏡像
命令如下:
docker pull nginx:latest
docker pull php:7.4-fpm
1、創(chuàng)建本地掛載路徑:
mkdir -p /docker/nginx/www/myphp (-p代表遞歸創(chuàng)建,按目錄層級創(chuàng)建目錄)
2、創(chuàng)建php容器
docker run --name myphp -v /docker/nginx/www/myphp:/www/myphp -d 鏡像ID
3、創(chuàng)建nginx本地掛在路徑:
mkdir -p /docker/nginx/conf/conf.d
4、nginx配置文件如下:
server {
listen 80;
server_name localhost; #這里修改成自己的域名,我這里是本地運(yùn)行所以填的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;
}
#當(dāng)請求網(wǎng)站下php文件的時候,反向代理到php-fpm
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/myphp/$fastcgi_script_name;
include fastcgi_params;
}
}
5、創(chuàng)建nginx容器:
docker run --name nginx1 -p 8090:80 -d -v /docker/nginx/www/myphp:/usr/share/nginx/html -v /docker/nginx/conf/conf.d:/etc/nginx/conf.d --link myphp:php nginx
PS:
# docker run --name nginx1 -p 8090:80 -d -v /docker/nginx/www/myphp:/usr/share/nginx/html -v /docker/nginx/conf/conf.d:/etc/nginx/conf.d --link myphp:php nginx
-v 本地目錄:容器內(nèi)目錄 -p 本地端口:容器端口 --link 數(shù)據(jù)庫容器名:數(shù)據(jù)庫容器別名
6、創(chuàng)建文件測試:
效果如下:文章來源:http://www.zghlxwxcb.cn/news/detail-646520.html
參考文章:nginx調(diào)用php原理文章來源地址http://www.zghlxwxcb.cn/news/detail-646520.html
到了這里,關(guān)于docker搭建nginx+php環(huán)境的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!