V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Recommended Services
Amazon Web Services
LeanCloud
New Relic
ClearDB
yagamil
V2EX  ›  云计算

docker 部署的 nginx PHP 找不到 PHP 文件问题

  •  
  •   yagamil · 2022-04-10 22:16:03 +08:00 · 2808 次点击
    这是一个创建于 718 天前的主题,其中的信息可能已经有所发展或是发生改变。

    搜了不少资料,还没有没有解决问题。

    docker run --name my-php-fpm -v D:/www:/www -d php:7.3-fpm
    
    docker run --name my-nginx -p 8080:80 -d \
        -v D:/www:/usr/share/nginx/html:ro \
        -v D:/conf/conf.d:/etc/nginx/conf.d:ro \
        --link my-php-fpm:php \
        nginx
    
    

    nginx 配置文件

    server {
        listen       80;
        server_name  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;
        }
    
        location ~ \.php$ {
            fastcgi_pass   php:9000; #启动 nginx 容器时--link my-php-fpm:设置的值 php
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    

    index.php 内容

    <?php
    echo phpinfo();
    

    浏览器打开 http://localhost:8080/index.php

    提示找不到文件,在请求头看到的服务器是 php ,应该是 php 那边没有找到文件?

    kenshin912
        1
    kenshin912  
       2022-04-10 22:44:16 +08:00
    PHP 容器名是 my-php-fpm 啊 , 你 Nginx 的配置文件里面 fastcgi_pass 那里也应该是这个啊.
    cnbattle
        2
    cnbattle  
       2022-04-10 23:35:39 +08:00 via Android   ❤️ 1
    nginx fastcgi 只是传递 php 文件的路径到 php-fpm ,不是传递文件

    nginx 容器 php 文件映射 /usr/share/nginx/html 目录

    则 phpfpm 容器,也要映射到 /usr/share/nginx/html 这样的目录下,要一致
    yagamil
        3
    yagamil  
    OP
       2022-04-11 00:18:15 +08:00
    @cnbattle 谢谢。问题就是在这里。
    php 映射到 /usr/share/nginx/html 这里,而 php 的配置文件 默认是在 /var/www/html .
    映射到 /var/www/html 即可了。
    julyclyde
        4
    julyclyde  
       2022-04-11 15:19:07 +08:00
    include 另一个文件才对
    缺一个参数
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1383 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:40 · PVG 07:40 · LAX 16:40 · JFK 19:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.