docker部署nginx+php的 各种坑

docker部署nginx+php的介绍很多,我也是安装上面的来部署,发现各种坑,在这给列举下,供大家参考。
1、安装好docker的nignx 和php
2、修改nginx.conf配置,加上php解析
其中
location ~ .php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t document_rootdocumentrootfastcgi_script_name;
fastcgi_pass 172.17.0.3:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}

出现502 gateway错误
这里的fastcgi_pass要是phprpm容器的内网ip地址,而不是127.0.0.1

出现404 file not found
其实nginx版本不通,document_root高版本已不支持,写成绝对路径,但大部署介绍写的是宿主机路径,这是错的。要写成phpfpm容器内的路径,如:/var/www/html
还有我在安装phpfpm时挂载文件时-v宿主机要写到:后面
还碰到进容器后无权限,要在-v挂载后加–privileged=true
有的说要去修改phpfpm的配置文件把listen 127.0.0.1改成0.0.0.0这是不需要的
以上应该就能访问通了

如果部署的时候有权限不足
那要把宿主机对应的html文件夹设置成777

有的需要php特殊插件
phpfrm内有docker-php-ext-install命令
进入phpfrm容器内执行即可,如扩展mysql执行 docker-php-ext-install pdo pdo_mysql
如果ext里面没有还可以用如下的

apt update #更新软件源
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev #安装各种库
docker-php-source extract #解压源码
cd /usr/src/php/ext/gd #gd源码文件夹
docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2 #准备编译
docker-php-ext-install gd #编译安装
php -m | grep gd

在所有环境都成功部署好后,有的在运行应用时,会出现"Primary script unknown"错误,一般这是由于nginx和php-fpm的用户不同导致的。把nginx.conf和php-fpm.d/www.conf 的user设为同一个就可以了。

posted @ 2020-09-25 09:20  30岁再次出发  阅读(2160)  评论(0编辑  收藏  举报