django - 使用 Docker 上传后端是 django 和前端是 Vue 的应用程序
问题描述
我正在开发一个使用这些技术的应用程序:
- Django 后端
- Vue JS 前端
- PostgreSQL 数据库
- Docker 作为容器
- Traefik 作为反向代理版本 1.7
- 雷迪斯。
- awscli
这是我用于 docker-compose 运行所有应用程序的production.yml文件:
version: '3'
volumes:
production_postgres_data: {}
production_postgres_data_backups: {}
production_traefik: {}
services:
django:
build:
context: .
dockerfile: ./compose/production/django/Dockerfile
image: goplus_backend_production_django
depends_on:
- postgres
- redis
env_file:
- ./.envs/.production/.django
- ./.envs/.production/.postgres
command: /start
volumes:
- ./static:/static # adding static & media file for django
- ./media:/media
vue:
build:
context: /root/goplus_front/new_dashboard_v2
container_name: new_dashboard_v2
environment:
- HOST=localhost
- PORT=8080
ports:
- "8080:8080"
depends_on:
- django
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: goplus_backend_production_postgres
volumes:
- production_postgres_data:/var/lib/postgresql/data
- production_postgres_data_backups:/backups
env_file:
- ./.envs/.production/.postgres
ports:
- "5432:5432"
traefik:
build:
context: .
dockerfile: ./compose/production/traefik/Dockerfile
image: goplus_backend_production_traefik
depends_on:
- django
# volumes:
# - production_traefik:/etc/traefik/acme
ports:
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"
redis:
image: redis:5.0
awscli:
build:
context: .
dockerfile: ./compose/production/aws/Dockerfile
env_file:
- ./.envs/.production/.django
volumes:
- production_postgres_data_backups:/backups
到现在为止一切都很好,如果我使用IP:80我被重定向到 Django 应用程序(管理面板),如果我使用IP:8080我被重定向到 Vue 应用程序。
现在的问题是我想使用域名而不是 IP 地址,我购买了一个域名并添加了 SSL,如果我尝试访问 Django 应用程序它工作正常,但如果我尝试访问 Vue 应用程序则无法正常工作。这是traefik.toml的配置文件,负责将请求重定向到 Django 或 Vue:
logLevel = "INFO"
defaultEntryPoints = ["http", "https"]
# Entrypoints, http and https
[entryPoints]
# http should be redirected to https
[entryPoints.http]
address = ":80"
# https is the default
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/etc/certs/<crt_file_name>.crt"
keyFile = "/etc/certs/<crt_key_file_name>.key"
[file]
[backends]
[backends.django]
[backends.django.servers.server1]
url = "http://django:5000"
[backends.vue]
[backends.vue.servers.server1]
url = "http://vue:8080"
[frontends]
[frontends.django]
backend = "django"
passHostHeader = true
[frontends.django.headers]
HostsProxyHeaders = ['X-CSRFToken']
[frontends.django.routes.dr1]
rule = "Host:<domain name>, <IP name>"
[frontends.vue]
backend = "vue"
[frontends.vue.routes.dr1]
rule = "Host:<domain name>;PathPrefixStrip:/dashboard"
因此,从该配置中,我希望如果有人尝试访问 Django 应用程序,他必须只使用完整域名,如果他想使用 Vue 应用程序,他必须使用DomainName/dashboard,它可以与 Django 应用程序一起正常工作,但我得到了 Vue 应用程序这些错误。 那么有什么帮助或建议来解决这个问题吗?
解决方案
推荐阅读
- lit-element - 当插槽在 lit-html 中没有子节点时做一些事情
- ruby-on-rails - 如何在多个模块上使用相同的类名?
- javascript - 如何动态创建n列?
- django - collectstatic 不会忽略指定的文件
- mysql - SQL 查询速度慢且不使用索引
- android - 如何将数据从一个活动中的单选框传递到另一个活动中的一系列复选框
- javascript - 如何强制 :fullscreen 伪类遵循与 :not(:fullscreen) 相同的规则?
- java - 如何检查 ImageInputStream 是否已经关闭?
- github - 计算 Github API 文件 SHA
- libreoffice - 如何使用选项卡关注 LibreOffice Base 中的子表单