docker配置nginx请参考这篇文章
[bspost cid="50" /]
1、下载PHP7镜像
docker pull php:7.4-fpm
2、启动容器
docker run -d --name myphp7 \
-p 9000:9000 \
-v /opt/nginx/html:/var/www/html \
--restart=always php:7.4-fpm
PS:注意,php挂载/var/www/html的路径和nginx的html挂载宿主机的同一位置
3、配置nginx
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
}
}
location ~ \.php(.*)$ {
root /var/www/html;
fastcgi_pass 172.17.0.3:9000; # php容器的ip地址
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;
include fastcgi_params;
}
4、验证
# 创建一个php文件,将下面内容保存到文件中
vim /opt/nginx/html/index.php
<?php
phpinfo();
?>
# 重启nginx
docker restart nginx
访问Nginx