我有一个婚礼申请,包括reactjs,nestjs和traefik。我来自主机的域名。我在https自动重定向方面遇到了一些问题。我不知道为什么traefik中间件可以很好地处理url api.xxx.net。但它不适用于有反应的客户。当我输入xxx.net时,这将导致主机默认的http页面。尝试将其更改为https,站点将使用ssl让enscrypt。请帮助我,我在码头配置错误-撰写或主机安装问题?谢谢你的帮助!
我的DNS记录: CNAME 0 xxx.net 14400 A@0 my_server_ip 14400 api 0 my_server_ip 14400
这是我的船坞。
version: "3.9"
services:
reverse-proxy:
image: traefik:v2.4
container_name: "traefik"
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
- "--entrypoints.web.http.redirections.entrypoint.permanent=true"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
- "--certificatesresolvers.myresolver.acme.email=my_email@gmail.com"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
ports:
- "443:443"
- "80:80"
- "8080:8080"
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
client:
env_file:
"./client/.env"
build:
context: client
dockerfile: ./Dockerfile
image: wedding_client
container_name: wedding-client-container
ports:
- "3000:3000"
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.wedding-client-container.rule=Host(`xxx.com`)"
- "traefik.http.routers.wedding-client-container.entrypoints=websecure"
- "traefik.http.routers.wedding-client-container.tls.certresolver=myresolver"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.redirs.entrypoints=web"
- "traefik.http.routers.redirs.middlewares=redirect-to-https"
server:
env_file:
"./server/.env"
build:
context: server
dockerfile: ./Dockerfile
image: wedding_server
container_name: wedding-server-container
labels:
- "traefik.enable=true"
- "traefik.http.routers.wedding-server-container.rule=Host(`api.xxx.com`)"
- "traefik.http.routers.wedding-server-container.entrypoints=websecure"
- "traefik.http.routers.wedding-server-container.tls.certresolver=myresolver"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.redirs.entrypoints=web"
- "traefik.http.routers.redirs.middlewares=redirect-to-https"
ports:
- "5001:5001"
restart: always
发布于 2022-10-06 08:14:26
这是我的解决方案:
version: "3.9"
services:
reverse-proxy:
image: traefik:v2.8
container_name: "traefik"
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
- "--entrypoints.web.http.redirections.entrypoint.permanent=true"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
- "--certificatesresolvers.myresolver.acme.email=abc@gmail.com"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
ports:
- "443:443"
- "80:80"
- "8080:8080"
restart: always
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
client:
env_file:
"./client/.env"
image: thanhdeveloper/wedding_client:latest
container_name: wedding-client-container
ports:
- "3000:3000"
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.wedding-client-container.rule=Host(`nhuthanhwedding.com`)"
- "traefik.http.routers.wedding-client-container.entrypoints=websecure"
- "traefik.http.routers.wedding-client-container.tls.certresolver=myresolver"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.redirs.entrypoints=web"
- "traefik.http.routers.redirs.middlewares=redirect-to-https"
server:
env_file:
"./server/.env"
image: thanhdeveloper/wedding_server:latest
container_name: wedding-server-container
labels:
- "traefik.enable=true"
- "traefik.http.routers.wedding-server-container.rule=Host(`gateway.nhuthanhwedding.com`)"
- "traefik.http.routers.wedding-server-container.entrypoints=websecure"
- "traefik.http.routers.wedding-server-container.tls.certresolver=myresolver"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"