如何调整我的Apache Docker配置,使其仅将一些URL路由到我的Docker django实例



我在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"开头?

您可以尝试apache重写引擎:

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

最新更新