caoyufei
V2EX  ›  问与答

docker nginx + PHP -fpm 502

  •  
  •   caoyufei · Aug 12, 2019 · 2479 views
    This topic created in 2490 days ago, the information mentioned may be changed or developed.
    • nginx
        try_files $uri =404;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    
    • nginx 没有 error log

    • php-fpm

        listen = 127.0.0.1:9000
        listen.backlog = -1
        listen.allowed_clients = 127.0.0.1
    
    docker run --name php -p 9000:9000 -v /xxx:/xxx -d php:v1
    docker run --name nginx -p 8080:80 -v /xxx:/xxx --link php:php -d nginx:v1
    

    访问 PHP 文件 502, 访问 HTML 正常

    这是哪配置有问题?还是?

    4 replies    2019-08-12 20:42:12 +08:00
    eslizn
        1
    eslizn  
       Aug 12, 2019
    建议先看看 docker network 部分
    xupefei
        2
    xupefei  
       Aug 12, 2019   ❤️ 1
    每个 container 的 127.0.0.1 是独立的。
    你需要让两个容器运行在同一个 network 上,然后用 link 命令把 php 的 hostname 暴露给 nginx,然后让 php 监听 0.0.0.0:9000 并 expose 9000 ; nginx 连到 php:9000。
    boks
        3
    boks  
       Aug 12, 2019   ❤️ 1
    执行:docker inspect php | grep "IPAddress"
    得到的地址就是 nginx 配置的地址
    caoyufei
        4
    caoyufei  
    OP
       Aug 12, 2019
    @eslizn @xupefei @boks
    问题解决了
    thx!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 06:21 · PVG 14:21 · LAX 23:21 · JFK 02:21
    ♥ Do have faith in what you're doing.