简体   繁体   中英

Docker: Apache2 container can not talk to php7.1 container

I have Apache2 and PHP-FPM running in two separate containers. Both containers run OK, but I'm unable to process php files. When I navigate to a php file the browsers responds with 'File not found.' Looking in the apache error log I get:

[Fri Feb 01 09:50:54.894531 2019] [proxy_fcgi:error] [pid 8:tid 140041300997888] [client 44.82.126.19:65344] AH01071: Got error 'Primary script unknown\n'

Principally I have been following the setup instructions here . Searches of other sites show similar setups.

I note that the instructions don't include the apache2 PHP module, but it seems fcgi takes care of this...?

Some debugging results:

  • I can visit the host IP and render an HTML web page.
  • Inside the Apache2 container I can ping the PHPcontainer successfully. So the internal network is working.
  • In the PHP container I can run CLI PHP commands successfully.
  • I have checked the PHP-FPM config file and "Docker inspect" for the exposure of port 9000. All OK.

docker-compose.yml:

version: '3.2'
volumes:
  apache2Config:
    external: true
  webContent:
    external: true
  databases:
    external: true

networks:
  frontend:
  backend:

services:
  php:
    build:
      context: './php7.1/'
      args:
        PHP_VERSION: ${PHP_VERSION}
    image: php7.1.26-fpm:1.0
    restart: always
    container_name: php
    networks:
      - backend
  web:
    build: ./apache2/
    image: apache2:1.0
    restart: always
    container_name: AOW_apache2Server
    depends_on:
      - php
      - mariadb
    networks:
      - frontend
      - backend
    expose:
     - "80"
     - "81"
     - "443"
     - "8083"
    ports:
     - "80:80/tcp"
     - "81:81"
     - "443:443"
     - "8083:8083"
    volumes:
      - apache2Config:/mnt/apache2Conf
      - webContent:/var/www
  mariadb:
    build: ./mariaDB/
    image: mariadb_10.4.0
    container_name: mariaDB_10.4.0
    networks:
      - backend
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=*****
    volumes:
      - databases:/var/lib/mysql

Apach2 config:

#ServerRoot "/etc/apache2"
ServerName aow

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn mod_rewrite.c:trace2

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

#Allow access to the /usr/share directory. phpmyadmin is located in here.
<Directory /usr/share/phpmyadmin/>
        Order allow,deny
        Allow from all
        Require all granted
</Directory>

#Allow access to the www directory. Mediawiki source files are in here.
#Directory listing is disabled, but following symLinks is allowed.
<Directory /var/www/>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent


# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

Apache2 enabled mods:

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cache_module (shared)
 cache_disk_module (shared)

 deflate_module (shared)

 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 file_cache_module (shared)
 filter_module (shared)
 headers_module (shared)
 macro_module (shared)
 mime_module (shared)
 mpm_event_module (shared)
 negotiation_module (shared)

 proxy_module (shared)
 proxy_fcgi_module (shared)

 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)

000-default.conf contents:

<VirtualHost *:80>
    # Proxy .php requests to port 9000 of the php-fpm container
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/$1

    ServerAdmin <<REMOVED>>
    DocumentRoot /var/www

    LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

This looks like an access issue. Have you made sure that the PHP/FPM container has access to the directory Apache is pointing to?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM