Docker:Apache2容器无法与php7.1容器通信
我在两个单独的容器中运行Apache2和PHP-FPM。两个容器运行正常,但我无法处理php文件。当我导航到一个php文件时,浏览器会以“未找到文件”响应。查看apache错误日志,我得到:Docker:Apache2容器无法与php7.1容器通信,php,docker-compose,apache2.4,Php,Docker Compose,Apache2.4,我在两个单独的容器中运行Apache2和PHP-FPM。两个容器运行正常,但我无法处理php文件。当我导航到一个php文件时,浏览器会以“未找到文件”响应。查看apache错误日志,我得到: [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'
[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'
原则上,我一直遵循安装说明。对其他网站的搜索显示了类似的设置
我注意到这些指令不包括apache2 PHP模块,但fcgi似乎解决了这个问题
一些调试结果:
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
#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
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)
<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>
- 我可以访问主机IP并呈现HTML网页
- 在Apache2容器中,我可以成功ping PHPcontainer。因此,内部网络正在工作
- 在PHP容器中,我可以成功运行CLI PHP命令
- 我已经检查了PHP-FPM配置文件和“Docker inspect”以查看端口9000的暴露情况。好的
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
#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
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)
<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>
Apach2配置:
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
#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
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)
<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>
000-default.conf内容:
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
#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
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)
<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>
#php请求php fpm容器的端口9000
ProxyPassMatch^/(.\.php(/.*)$fcgi://php:9000/var/www/$1
服务器管理员
DocumentRoot/var/www
日志级别信息ssl:警告
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
这看起来像是一个访问问题。您是否确保PHP/FPM容器可以访问Apache指向的目录?刚刚注意到DocumentRoot与ProxyPassMatch中的路径不同。不确定这是否重要,但要到星期一才能测试。我调用的PHP文件位于两个位置。