docker-compose文件如下
version: "3"
services:
################################################################
# traefik
################################################################
reverse-proxy:
# The official v2 Traefik docker image
image: traefik:v2.4
environment:
- TZ=Asia/Shanghai
# Enables the web UI and tells Traefik to listen to docker
command:
# - --log.level=DEBUG
- --accesslog=true
- --accesslog.fields.names.StartUTC=drop
- --api.insecure=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.http.address=:80
restart: always
ports:
# The HTTP port
- "80:80"
# The HTTPs port
- "443:443"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- consul
# - jaeger
labels:
# * 代表允许所有的域名
- "traefik.http.middlewares.my-cors-plugin.plugin.cors.allowedOrigins=*"
# 设置为 true == 你的应用需要发送 cookies 或者 HTTP 认证信息
- "traefik.http.middlewares.my-cors-plugin.plugin.cors.allowCredentials=false"
# 设置 RESTAPI 请求方式,多个用","隔开
#- "traefik.http.middlewares.my-cors-plugin.plugin.cors.allowedMethods=GET,POST"
# 请求头中必须要包含的参数名
- "traefik.http.middlewares.my-cors-plugin.plugin.cors.allowedHeaders=Authorization,Content-Type"
# 定义了预检请求的结果可以被缓存多久
- "traefik.http.middlewares.my-cors-plugin.plugin.cors.maxAge=3600"
- "traefik.http.routers.my-service-router.middlewares=my-cors-plugin@docker"