【问题标题】:How do I adjust my Apache Docker config to only route some URLs to my Docker django instance?如何调整我的 Apache Docker 配置以仅将一些 URL 路由到我的 Docker django 实例?
【发布时间】:2020-07-10 08:22:21
【问题描述】:

我在 Docker 容器中设置了 Apache、Django 和 MySql 映像。下面是我的 docker-compose.yml 文件...

version: '3'

services:
  mysql:
    restart: always
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: 'maps_data'
      # So you don't have to use root, but you can if you like
      MYSQL_USER: 'chicommons'
      # You can use whatever password you like
      MYSQL_PASSWORD: 'password'
      # Password for root access
      MYSQL_ROOT_PASSWORD: 'password'
    ports:
      - "3406:3306"
    volumes:
      - my-db:/var/lib/mysql
    command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']

  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 maps.wsgi:application --reload -w 2 -b :8000
    volumes:
    - ./web/:/app
    depends_on:
      - mysql

  apache:
    restart: always
    build: ./apache/
    ports:
      - "9090:80"
    #volumes:
    #  - web-static:/www/static
    links:
      - web:web

volumes:
  my-db:

在我的 Apache 配置中,我设置了这个虚拟主机来将流量路由到我的 Django 实例...

<VirtualHost *:80>
    ServerName maps.example.com

    ProxyPreserveHost On
    ProxyPass / http://web:8000/
    ProxyPassReverse / http://web:8000/

    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</VirtualHost>

我的问题是,如何更改上述配置以仅向我的 Django 实例发送流量,其中 URL 以“data”或“coops”开头?

【问题讨论】:

    标签: django apache docker docker-compose proxypass


    【解决方案1】:

    你可以试试apache重写引擎:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} data
    RewriteRule ^/(.*)$ http://doamin or webapp/$1 [L,R=301]
    

    【讨论】:

    • 谢谢,但您的回答是真正的答案,还是您只是说一般使用 RewriteEngine?我在您的答案中没有看到任何“数据”或“合作”块,这是我试图由我的 Django 图像处理的 URL。
    猜你喜欢
    • 2020-06-02
    • 2020-05-25
    • 1970-01-01
    • 2020-09-22
    • 2023-02-09
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多