多容器搭建 php-fpm + nginx, 在测试 nginx 的配置是否成功与 fpm 连通时,访问 url,
每次都报 File not found.
nginx 的日志如下:

核心的问题: FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
docker logs php-fpm 的日志如下:

nginx 的日志如下:
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass php_180227_7.1.0:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
nginx 的共享目录如下(/home/docker_lnmp/nginx/www:/usr/share/nginx/html):

php 的共享目录如下(/home/docker_lnmp/nginx/www:/var/www/html):

nginx 配置文件 config 中
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
要换成
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
不然 php fastcgi解析不了目录
本文讲述了在搭建多容器环境的PHP-FPM与Nginx集成时遇到的404问题,发现是由于Nginx配置中的SCRIPT_FILENAME未正确设置导致FastCGI解析失败。通过调整配置解决了FastCGI发送到stderr的Primaryscriptunknown错误。
1451

被折叠的 条评论
为什么被折叠?



