在我的 Apache Docker 容器中,如何设置代理来路由其他代理未处理的所有内容?
In my Apache Docker container, how do I set up a Proxy to route everything not handled by other proxys?
我在 Mac 上使用 Docker 19。在我的 docker-compose.yml 文件中,我有几个容器、一个数据库、Python 后端应用程序、一个网络服务器 (Apache) 和我的客户端应用程序 (React) .. .
web:
restart: always
build: ./web
ports: # to access the container from outside
- "8000:8000"
env_file: .env
environment:
DEBUG: 'true'
command: /usr/local/bin/gunicorn directory.wsgi:application --reload -w 2 -b :8000
volumes:
- ./web/:/app
depends_on:
- mysql
client:
build:
context: ./client
volumes:
- ./client:/app
ports:
- '3001:3000'
restart: always
container_name: web-app
environment:
- NODE_ENV=dockerdev
depends_on:
- web
stdin_open: true
command: /bin/bash /app/install_and_run.sh
apache:
restart: always
build: ./apache/
ports:
- "9090:80"
links:
- web:web
- client:client
在我的 Apache 虚拟主机配置 (apache/my-vhosts.conf) 中,我想将一些 URL 发送到我的 Python (web) 容器,并将其他所有内容发送到我的 React 容器,所以我尝试了
<VirtualHost *:80>
ServerName directory.example.com
ProxyPreserveHost On
ProxyPass / http://client:3001/
ProxyPassReverse / http://client:3001/
ProxyPass /coops/ http://web:8000/coops/
ProxyPassReverse /coops/ http://web:8000/coops/
ProxyPass /coop_types/ http://web:8000/coop_types/
ProxyPassReverse /coop_types/ http://web:8000/coop_types/
ProxyPass /people/ http://web:8000/people
ProxyPassReverse /people/ http://web:8000/people
ProxyPass /data http://web:8000/data
ProxyPassReverse /data http://web:8000/data
ProxyPass /countries/ http://web:8000/countries/
ProxyPassReverse /countries/ http://web:8000/countries/
ProxyPass /states/ http://web:8000/states/
ProxyPassReverse /states/ http://web:8000/states/
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</VirtualHost>
然而,当我开始一切时
docker-compose up
我尝试访问
http://localhost:9090/
我在日志中收到以下错误
apache_1 | [Sun Sep 27 20:30:42.880105 2020] [proxy_http:error] [pid 8:tid 140480125859584] [client 192.168.0.1:52882] AH01114: HTTP: failed to make connection to backend: web-app
apache_1 | 192.168.0.1 - - [27/Sep/2020:20:30:42 +0000] "GET / HTTP/1.1" 503 299
apache_1 | [Sun Sep 27 20:30:42.975438 2020] [proxy:error] [pid 8:tid 140480215029504] (111)Connection refused: AH00957: HTTP: attempt to connect to 192.168.0.5:3001 (web-app) failed
apache_1 | [Sun Sep 27 20:30:42.975505 2020] [proxy_http:error] [pid 8:tid 140480215029504] [client 192.168.0.1:52888] AH01114: HTTP: failed to make connection to backend: web-app, referer: http://localhost:9090/
我的页面没有出现(报告服务不可用)。设置 ProxyPass 以连接到我的应用程序的正确方法是什么?
您需要为客户端应用程序选择内部端口
ProxyPass / http://client:3000/
ProxyPassReverse / http://client:3000/
我在 Mac 上使用 Docker 19。在我的 docker-compose.yml 文件中,我有几个容器、一个数据库、Python 后端应用程序、一个网络服务器 (Apache) 和我的客户端应用程序 (React) .. .
web:
restart: always
build: ./web
ports: # to access the container from outside
- "8000:8000"
env_file: .env
environment:
DEBUG: 'true'
command: /usr/local/bin/gunicorn directory.wsgi:application --reload -w 2 -b :8000
volumes:
- ./web/:/app
depends_on:
- mysql
client:
build:
context: ./client
volumes:
- ./client:/app
ports:
- '3001:3000'
restart: always
container_name: web-app
environment:
- NODE_ENV=dockerdev
depends_on:
- web
stdin_open: true
command: /bin/bash /app/install_and_run.sh
apache:
restart: always
build: ./apache/
ports:
- "9090:80"
links:
- web:web
- client:client
在我的 Apache 虚拟主机配置 (apache/my-vhosts.conf) 中,我想将一些 URL 发送到我的 Python (web) 容器,并将其他所有内容发送到我的 React 容器,所以我尝试了
<VirtualHost *:80>
ServerName directory.example.com
ProxyPreserveHost On
ProxyPass / http://client:3001/
ProxyPassReverse / http://client:3001/
ProxyPass /coops/ http://web:8000/coops/
ProxyPassReverse /coops/ http://web:8000/coops/
ProxyPass /coop_types/ http://web:8000/coop_types/
ProxyPassReverse /coop_types/ http://web:8000/coop_types/
ProxyPass /people/ http://web:8000/people
ProxyPassReverse /people/ http://web:8000/people
ProxyPass /data http://web:8000/data
ProxyPassReverse /data http://web:8000/data
ProxyPass /countries/ http://web:8000/countries/
ProxyPassReverse /countries/ http://web:8000/countries/
ProxyPass /states/ http://web:8000/states/
ProxyPassReverse /states/ http://web:8000/states/
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</VirtualHost>
然而,当我开始一切时
docker-compose up
我尝试访问
http://localhost:9090/
我在日志中收到以下错误
apache_1 | [Sun Sep 27 20:30:42.880105 2020] [proxy_http:error] [pid 8:tid 140480125859584] [client 192.168.0.1:52882] AH01114: HTTP: failed to make connection to backend: web-app
apache_1 | 192.168.0.1 - - [27/Sep/2020:20:30:42 +0000] "GET / HTTP/1.1" 503 299
apache_1 | [Sun Sep 27 20:30:42.975438 2020] [proxy:error] [pid 8:tid 140480215029504] (111)Connection refused: AH00957: HTTP: attempt to connect to 192.168.0.5:3001 (web-app) failed
apache_1 | [Sun Sep 27 20:30:42.975505 2020] [proxy_http:error] [pid 8:tid 140480215029504] [client 192.168.0.1:52888] AH01114: HTTP: failed to make connection to backend: web-app, referer: http://localhost:9090/
我的页面没有出现(报告服务不可用)。设置 ProxyPass 以连接到我的应用程序的正确方法是什么?
您需要为客户端应用程序选择内部端口
ProxyPass / http://client:3000/
ProxyPassReverse / http://client:3000/