dongyongmin5711 2017-09-18 06:26 采纳率: 100%
浏览 765
已采纳

如何通过unix socket设置Apache2和PHP-FPM?

我尝试通过unix套接字设置Apache2和PHP-FPM,但结果是 (111)连接被拒绝:AH02454:FCGI:尝试连接到Unix域套接字/run/php/php7.2-fpm.sock(*)失败 docker-compose.yml

version: "2"
services:
    php:
        build: "php:7.2-rc-alpine"
        container_name: "php"
        volumes:
            - "./code:/usr/local/apache2/htdocs"
            - "./php7.2-fpm.sock:/run/php/php7.2-fpm.sock"
    apache2:
        build: "httpd:2.4-alpine"
        container_name: "apache2"
        volumes:
            - "./code:/usr/local/apache2/htdocs"
            - "./php7.2-fpm.sock:/run/php/php7.2-fpm.sock"
        ports:
            - 80:80
        links:
            - php

www.conf

listen = /run/php/php7.2-fpm.sock

httpd-vhosts.conf

<FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost/"
</FilesMatch>

但是通过TCP连接时可以使用。

www.conf

listen = 127.0.0.1:9000

httpd-vhosts.conf

<FilesMatch \.php$>
    SetHandler "proxy:fcgi://php:9000"
</FilesMatch>
  • 写回答

1条回答 默认 最新

  • dongsu3664 2017-09-20 15:33
    关注

    Okie, so have the repo helped to fix the issue.

    Issue #1 - www.conf being copied in apache container

    You had below statement in your apache container Dockerfile

    COPY ./www.conf /usr/local/etc/php-fpm.d/www.conf
    

    This is actually intended for the php container which will be running php-fpm and not the apache container

    Issue #2 - Socket was never being created

    Your volume bind - "./php7.2-fpm.sock:/run/php/php7.2-fpm.sock" was creating the socket and they were not being created by php-fpm as such. So you created a blank file and trying to connect to it won't do anything

    Issue #3 - No config in php to create socket

    The docker container by default create listen to 0.0.0.0:9000 inside the fpm container. You needed to override the zz-docker.conf file inside the container to fix the issue.

    zz-docker.conf

    [global]
    daemonize = no
    
    [www]
    listen = /run/php/php7.2-fpm.sock
    listen.mode = 0666
    
    Updated docker file
    FROM php:7.2-rc-fpm-alpine
    
    LABEL maintainer="Eakkapat Pattarathamrong (overbid@gmail.com)"
    RUN docker-php-ext-install \
            sockets
    
    RUN set -x \
            && deluser www-data \
            && addgroup -g 500 -S www-data \
            && adduser -u 500 -D -S -G www-data www-data
    
    COPY php-fpm.d /usr/local/etc/php-fpm.d/
    

    Issue #4 - Sockets being shared as volumes to host

    You should be sharing sockets using a named volume, so the socket should not be on host at all.

    Updated docker-compose.yml
    version: "2"
    services:
        php:
            build: "./php"
            container_name: "php"
            volumes:
                - "./code:/usr/local/apache2/htdocs"
                - "phpsocket:/run/php"
        apache2:
            build: "./apache2"
            container_name: "apache2"
            volumes:
                - "./code:/usr/local/apache2/htdocs"
                - "phpsocket:/run/php"
            ports:
                - 7080:80
            links:
                - php
    volumes:
      phpsocket:
    

    After fixing all the issues I was able to get the php page working

    PHP-FPM

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示