php-fpm 在docker中运行
nginx在容器中, php也在容器中,在容器中的好处是,可以自由切换版本 docker run -d -v /home/docker/nginx-ui/etc/www:/var/www/html/php74 -p 9000:9000 --name php74 php:7.4-fpm
注意, php运行的脚本在容器的 /var/www/html/php74
Nginx运行php
nginx上运行php,是通过代理的,把请求通过socket转发到其它容器,例如上面的 php74 容器.
主要是配置 fastcgi_pass , 指向php-fpm的IP+端口
另外一个配置就是php的root路径, fastcgi_param SCRIPT_FILENAME 该值要配置对
/var/www/html/php74/$fastcgi_script_name ,其中 /var/www/html/php74 路径是 php容器内 php-fpm的路径,需注意.
server {
listen 80;
listen [::]:80;
server_name php.us.aico.vip;
root /etc/nginx-ui/www;
index index.php index.html index.htm;
location / {
index index.php
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .*\.php(\/.*)*$ {
# 开启 fastcgi 模式
fastcgi_pass 172.17.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/php74/$fastcgi_script_name;
include fastcgi_params;
}
#unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^(.*)$ /index.php$1 last;
break;
}
}
root /etc/nginx-ui/www 这个值是nginx 容器内 运行html的路径哦.
最后一次更新于2025-04-07


