在 Docker Compose 上使用 Apache2 反向代理的 BaGet 不工作
BaGet with Apache2 Reverse Proxy on Docker Compose not working
我正在尝试在 Docker 中使用 Docker Compose 在 Apache2 反向代理后面设置 BaGet,其中 Apache2 也在 运行 中 Docker来自 Docker 撰写。
我已经使用 Jenkins 和 Sonar 成功完成了这项工作,但是使用 BaGet (http://localhost:8000/baget) 我得到“服务不可用”,即使它可以直接在其自己的端口上使用,例如:http: //localhost:5555/.
我的 Docker 撰写文件如下所示:
version: "3"
services:
smtp:
container_name: smtp
image: namshi/smtp
jenkins:
container_name: jenkins
build: ./jenkins/
environment:
- JENKINS_OPTS="--prefix=/jenkins"
sonar:
container_name: sonar
image: sonarqube:latest
environment:
- SONAR_WEB_CONTEXT=/sonar
baget:
container_name: baget
image: loicsharma/baget:latest
ports:
- "5555:80"
environment:
- PathBase=/baget
apache:
container_name: apache
build: ./apache/
ports:
- "8000:80"
我的 Apache2 Docker 文件如下所示:
FROM debian:stretch
RUN apt-get update
RUN apt-get install -y apache2 && apt-get clean
RUN a2enmod proxy
RUN a2enmod proxy_http
RUN a2dissite 000-default.conf
COPY devenv.conf /etc/apache2/sites-available/devenv.conf
RUN a2ensite devenv
EXPOSE 80
CMD apachectl -D FOREGROUND
我的 Apache2 配置文件是这样的:
<VirtualHost *:80>
ServerAdmin ...
ServerName ...
ServerAlias devenv
ProxyRequests Off
AllowEncodedSlashes NoDecode
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass /jenkins http://jenkins:8080/jenkins nocanon
ProxyPassReverse /jenkins http://jenkins:8080/jenkins nocanon
ProxyPass /sonar http://sonar:9000/sonar nocanon
ProxyPassReverse /sonar http://sonar:9000/sonar nocanon
ProxyPass /baget http://baget:5555/baget nocanon
ProxyPassReverse /baget http://baget:5555/baget nocanon
</VirtualHost>
我尝试了各种不同的 ProxyPass URL 组合,我尝试使用 localhost 而不是内部 Docker 编写服务名称,我尝试了不同的端口并且我尝试了 运行 没有 PathBase 环境变量的 BaGet,没有任何效果!
我希望这对我的配置来说是显而易见的,而不是 BaGet 的奇怪之处。
所以,我使用了错误的端口:
ProxyPass /baget http://baget:5555/baget nocanon
ProxyPassReverse /baget http://baget:5555/baget nocanon
应该是:
ProxyPass /baget http://baget/baget nocanon
ProxyPassReverse /baget http://baget/baget nocanon
Docker Docker Compose 中的容器在内部映射端口上相互通信,而不是外部端口。现在我知道,这非常有道理!
我正在尝试在 Docker 中使用 Docker Compose 在 Apache2 反向代理后面设置 BaGet,其中 Apache2 也在 运行 中 Docker来自 Docker 撰写。
我已经使用 Jenkins 和 Sonar 成功完成了这项工作,但是使用 BaGet (http://localhost:8000/baget) 我得到“服务不可用”,即使它可以直接在其自己的端口上使用,例如:http: //localhost:5555/.
我的 Docker 撰写文件如下所示:
version: "3"
services:
smtp:
container_name: smtp
image: namshi/smtp
jenkins:
container_name: jenkins
build: ./jenkins/
environment:
- JENKINS_OPTS="--prefix=/jenkins"
sonar:
container_name: sonar
image: sonarqube:latest
environment:
- SONAR_WEB_CONTEXT=/sonar
baget:
container_name: baget
image: loicsharma/baget:latest
ports:
- "5555:80"
environment:
- PathBase=/baget
apache:
container_name: apache
build: ./apache/
ports:
- "8000:80"
我的 Apache2 Docker 文件如下所示:
FROM debian:stretch
RUN apt-get update
RUN apt-get install -y apache2 && apt-get clean
RUN a2enmod proxy
RUN a2enmod proxy_http
RUN a2dissite 000-default.conf
COPY devenv.conf /etc/apache2/sites-available/devenv.conf
RUN a2ensite devenv
EXPOSE 80
CMD apachectl -D FOREGROUND
我的 Apache2 配置文件是这样的:
<VirtualHost *:80>
ServerAdmin ...
ServerName ...
ServerAlias devenv
ProxyRequests Off
AllowEncodedSlashes NoDecode
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass /jenkins http://jenkins:8080/jenkins nocanon
ProxyPassReverse /jenkins http://jenkins:8080/jenkins nocanon
ProxyPass /sonar http://sonar:9000/sonar nocanon
ProxyPassReverse /sonar http://sonar:9000/sonar nocanon
ProxyPass /baget http://baget:5555/baget nocanon
ProxyPassReverse /baget http://baget:5555/baget nocanon
</VirtualHost>
我尝试了各种不同的 ProxyPass URL 组合,我尝试使用 localhost 而不是内部 Docker 编写服务名称,我尝试了不同的端口并且我尝试了 运行 没有 PathBase 环境变量的 BaGet,没有任何效果!
我希望这对我的配置来说是显而易见的,而不是 BaGet 的奇怪之处。
所以,我使用了错误的端口:
ProxyPass /baget http://baget:5555/baget nocanon
ProxyPassReverse /baget http://baget:5555/baget nocanon
应该是:
ProxyPass /baget http://baget/baget nocanon
ProxyPassReverse /baget http://baget/baget nocanon
Docker Docker Compose 中的容器在内部映射端口上相互通信,而不是外部端口。现在我知道,这非常有道理!