Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复在Docker容器中运行的Apache中不可用的503服务?_Apache_Docker_Virtualhost_Http Proxy_Http Error - Fatal编程技术网

如何修复在Docker容器中运行的Apache中不可用的503服务?

如何修复在Docker容器中运行的Apache中不可用的503服务?,apache,docker,virtualhost,http-proxy,http-error,Apache,Docker,Virtualhost,Http Proxy,Http Error,我正在尝试在Docker容器中创建Apache虚拟主机代理(我在Docker 1.6上),因此我执行了以下操作: a2ensite build.example.conf a2ensite cicd.example.conf service apache2 restart [Mon Oct 16 21:17:32.510127 2017] [proxy:error] [pid 165:tid 140552167175936] (111)Connection refused: AH00957: H

我正在尝试在Docker容器中创建Apache虚拟主机代理(我在Docker 1.6上),因此我执行了以下操作:

a2ensite build.example.conf
a2ensite cicd.example.conf
service apache2 restart
[Mon Oct 16 21:17:32.510127 2017] [proxy:error] [pid 165:tid 140552167175936] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
[Mon Oct 16 21:17:32.510278 2017] [proxy:error] [pid 165:tid 140552167175936] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
[Mon Oct 16 21:17:32.510302 2017] [proxy_http:error] [pid 165:tid 140552167175936] [client 172.26.16.120:61391] AH01114: HTTP: failed to make connection to backend: localhost
[Mon Oct 16 21:17:32.799053 2017] [proxy:error] [pid 166:tid 140552217532160] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
[Mon Oct 16 21:17:32.799232 2017] [proxy:error] [pid 166:tid 140552217532160] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
[Mon Oct 16 21:17:32.799256 2017] [proxy_http:error] [pid 166:tid 140552217532160] [client 172.26.16.120:61392] AH01114: HTTP: failed to make connection to backend: localhost, referer: http://build.example.com:8000/info.php
首先设置两个Docker容器,每个容器运行各自的web应用程序:

docker run -it -p 8001:80 -p 4431:443 --name build ubuntu:latest

apt-get update
apt-get install apache2 libapache2-mod-php -y
echo “<?php phpinfo(); ?>” >> /var/www/html/info.php
service apache2 restart
在8000端口,它自己就可以完美地工作

然后,我为其他每个Docker容器创建了一个虚拟主机文件:

<VirtualHost *:80>
    ServerName build.example.com
    <Proxy *>
        Allow from localhost
    </Proxy>
    ProxyPass / http://localhost:8001/
</VirtualHost>
apache_proxy
容器的命令行运行
apachectl-S
,我可以看到以下内容生效:

VirtualHost configuration:
*:80 is a NameVirtualHost
     default server 172.17.0.17 (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost 172.17.0.17 (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost build.example.com (/etc/apache2/sites-enabled/build.example.conf:1)
     port 80 namevhost cicd.example.com (/etc/apache2/sites-enabled/cicd.example.conf:1)
以下是安装程序的外观:

我可以通过每个容器各自的端口访问每个容器,我应该能够访问以下URL以访问各个站点:

build.example.com:8000应该代理端口8001上的容器/网站 cicd.example.com:8000应该代理8002端口上的容器/网站

相反,我得到了以下错误:

503服务不可用

通过检查日志,我得到以下信息:

a2ensite build.example.conf
a2ensite cicd.example.conf
service apache2 restart
[Mon Oct 16 21:17:32.510127 2017] [proxy:error] [pid 165:tid 140552167175936] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
[Mon Oct 16 21:17:32.510278 2017] [proxy:error] [pid 165:tid 140552167175936] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
[Mon Oct 16 21:17:32.510302 2017] [proxy_http:error] [pid 165:tid 140552167175936] [client 172.26.16.120:61391] AH01114: HTTP: failed to make connection to backend: localhost
[Mon Oct 16 21:17:32.799053 2017] [proxy:error] [pid 166:tid 140552217532160] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
[Mon Oct 16 21:17:32.799232 2017] [proxy:error] [pid 166:tid 140552217532160] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
[Mon Oct 16 21:17:32.799256 2017] [proxy_http:error] [pid 166:tid 140552217532160] [client 172.26.16.120:61392] AH01114: HTTP: failed to make connection to backend: localhost, referer: http://build.example.com:8000/info.php
在过去的几个小时里,我一直在胡思乱想,试图让它发挥作用,我确信现在我错过了一些非常简单的事情。有人能解释我的错误吗

注 我跟踪了一个关于SELinux的大兔子洞,它没有启用,甚至没有真正安装在Ubuntu/Apache代理容器中

我还应该声明,我不是网络专家或web服务器配置大师。我只知道会很危险

编辑 根据建议,我尝试了以下方法:

a2ensite build.example.conf
a2ensite cicd.example.conf
service apache2 restart
[Mon Oct 16 21:17:32.510127 2017] [proxy:error] [pid 165:tid 140552167175936] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
[Mon Oct 16 21:17:32.510278 2017] [proxy:error] [pid 165:tid 140552167175936] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
[Mon Oct 16 21:17:32.510302 2017] [proxy_http:error] [pid 165:tid 140552167175936] [client 172.26.16.120:61391] AH01114: HTTP: failed to make connection to backend: localhost
[Mon Oct 16 21:17:32.799053 2017] [proxy:error] [pid 166:tid 140552217532160] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
[Mon Oct 16 21:17:32.799232 2017] [proxy:error] [pid 166:tid 140552217532160] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
[Mon Oct 16 21:17:32.799256 2017] [proxy_http:error] [pid 166:tid 140552217532160] [client 172.26.16.120:61392] AH01114: HTTP: failed to make connection to backend: localhost, referer: http://build.example.com:8000/info.php
ProxyPass/http://cicd:80/
导致502错误
ProxyPass/http://ip.address.of.server:8002/
超时
ProxyPass/http://ip.address.of.container:8002/
导致503错误

ProxyPass/http://127.0.0.1:8002/ retry=0
会导致503错误(在其他答案中建议)

您的另外两个容器不是localhost,而是各自的

  • 建造:80
  • cicd:80

在你的apache代理中反映出来,你应该很乐意去

我真正需要记住的是,一旦我们传入请求,我们就在Docker的网络中工作,所以使用
ProxyPass/http://localhost:8002/
将不起作用,因为“localhost”属于我们发出请求的Docker容器

所以我开始在错误框外搜索,可以这么说,并得到了这个答案

我确定的是我们需要将请求传递给Docker网络。为了获取这些信息,我从服务器的命令行运行了sudo ip addr show docker0,它返回:

4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff
    inet 172.17.42.1/16 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::5484:7aff:fefe:9799/64 scope link
       valid_lft forever preferred_lft forever

您是否尝试过echo net.ipv4.ip_forward=1?无需担心,请重新阅读您的设置,您不需要它;为什么要将代理反转为localhost:8001?8001是导出到主机的端口,而httpd正在另一个容器中运行@ᴳᵁᴵᴰᴼ 是,8001暴露于容器内端口80的主机。看一下添加的图表。因此我应该将
ProxyPass
更改为
/http://build.example.com:8001
/http://cicd.example.com:8002
?更可能的版本:80和cicd:80@ᴳᵁᴵᴰᴼ 对的您为容器指定的名称最终是在容器之间的docker网络中已知的主机名。因此,只需build:8001和build:8002,因为它们是端口。它们分别使用
-p 8001:80
-p 8002:80
运行,现在无法对其进行测试,但我相信您会使用端口80,因为它是容器中打开的端口;不是80XX,它是转发到主机的端口。你找到了一个解决方案。您可能希望修复另一个容器的IP(),因为您的容器IP在不同的运行中可能会有所不同修复另一个容器的IP?抱歉,我没有关注@b.enoit.be-你是说
构建
?如果是这样的话,我就这样做了,举个例子,在一个容器的运行时,您可以指定它将使用的IP,这样您就不会出现意外的“以前是那个IP,但现在我重新启动了它,它有一个不同的IP”。Docker的行为类似于DHCP,只是将IP分配给您的容器。因此,在一次运行到另一次运行时,同一容器的IP地址可能不相同。对-哦,是的,在生产设置中,我确保IP已分配并“固定”@b.enoit.beI我不确定这是否是您真正想要的:使用当前配置,打开
localhost:8080
后的步骤是:1。8080的本地套接字连接到代理容器端口802。代理容器代理回端口8001上的主机(172.17.42.1是docker网络的网关,即它与本地主机是同一主机)3。主机上的端口8001连接到cicd容器端口80 4。cicd提供php页面。基本上,您将进入,并且代理通过主机本身向另一个“入”端节点代理