Docker php curl 连接被拒绝

【下图演示】

开发商您好!最近我试图对一个 php 网站进行 dockerize,但是当我尝试从一个网站卷曲到另一个网站时,连接被拒绝。

基本上我有三个网站:

  • 应用程序编程接口

  • 第一站点

  • 第二站点

问题是connection is refused when I try to call api from first-site.

./docker-compose.yml

version: "3.1"

services:

  www:

    build: ./www/.

    ports:

      - "0.0.0.0:8080:80"

      - "0.0.0.0:443:443"

    volumes:

      - ./htdocs:/var/www

      - ./www/conf:/etc/httpd/conf

    networks:

      - local


  php:

    build: ./php/.

    ports:

      - '9000'

    volumes:

      - ./htdocs:/var/www

    networks:

      - local


networks:

  local:

    driver: bridge

./www/Dockerfile


FROM centos:8.2.2004

MAINTAINER kenphanith <https://github.com/kenphanith>


LABEL description="develop environment"

LABEL httpd_version="2.4"


RUN dnf -yq module install httpd:2.4 && \

    dnf -yq install epel-release && \

    dnf -yq install mod_perl ImageMagick && \

    dnf clean all

RUN sscg -q \

    --cert-file     /etc/pki/tls/certs/localhost.crt \

    --cert-key-file /etc/pki/tls/private/localhost.key \

    --ca-file       /etc/pki/tls/certs/localhost.crt \

    --lifetime      365 \

    --hostname      localhost \

    --email         root@localhost



EXPOSE 80/tcp 443/tcp

WORKDIR /var/www

CMD ["/usr/sbin/apachectl","-D","FOREGROUND"]

我里面./www/conf

  • /vhost.d

    • /ssl

    • 第一站点配置文件

    • 第二个站点.conf

    • 接口配置文件

  • httpd.conf

第一站点配置文件

<VirtualHost *:80>

    ServerName firstsite.com

    DocumentRoot /var/www/firstsite


    <Directory "/var/www/firstsite">

        Options -Indexes +FollowSymLinks

        DirectoryIndex index.php index.html


        <FilesMatch \.php$>

            SetHandler "proxy:fcgi://php:9000"

        </FilesMatch>

    </Directory>


</VirtualHost>


<VirtualHost *:443>

    ServerName firstsite

    DocumentRoot /var/www/firstsite

</VirtualHost>


守着星空守着你
浏览 139回答 1
1回答

手掌心

您的服务名称是可联网的。例如,我可以输入mariadb数据库连接而不是localhostIP。在下面的示例中,awesome.scot是我的 Apache 服务器,您会注意到另一个名为 的服务器app,它实际上只是挂载文件,因此可以为每个网站添加一项服务!如果您引用服务名称,您的呼叫将毫无问题地完成:-)这是我的 LAMP sdtack 的 Docker 撰写文件。它还附带 mailhog、自签名 ssl、xdebug 等。version: '2'volumes:    db_data:        driver: localservices:    awesome.scot:        build: ./build/httpd        links:            - php        ports:            - 80:80            - 443:443        volumes_from:            - app    php:        build: ./build/php        ports:            - 9000            - 9001        volumes_from:            - app        links:            - mariadb            - mail        environment:            APPLICATION_ENV: 'development'        user: php:staff    app:        image: httpd:2.4.38        volumes:            - ./:/var/www/html        command: "echo true"    mariadb:        image: mariadb:latest        volumes:            - ./build/data:/docker-entrypoint-initdb.d            - db_data:/var/lib/mysql        environment:            MYSQL_ROOT_PASSWORD: '[123456]'            MYSQL_USER: dbuser            MYSQL_PASSWORD: '[123456]'        ports:            - 3306:3306    mail:        image: mailhog/mailhog        ports:            - 1025:1025            - 8025:8025
打开App,查看更多内容
随时随地看视频慕课网APP