在我的Apache Docker容器中,如何设置代理来路由其他代理未处理的所有内容?

时间:2020-09-27 20:53:54

标签: apache docker docker-compose virtualhost proxypass

我在Mac上使用Docker 19。在我的docker-compose.yml文件中,我有几个容器,一个数据库,一个Python后端应用程序,一个Web服务器(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连接到我的应用程序的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

您需要为客户端应用选择内部端口

   ProxyPass / http://client:3000/
   ProxyPassReverse / http://client:3000/
相关问题