我正在使用 traefik 版本 2(或 2.x),我想使用 traefik 路由器将所有请求从端口 80 转发到不同的端口,如 8081。所以像http://localhost/xx这样的请求将被转发到http://localhost:8081/xx URL。
我是 traefik 的新手,我正在使用 docker 进行此配置。下面是我的 docker-compose.yml 文件配置。配置此 traefik 仪表板后,会在http://localhost:8080/dashboard/#/ URL上加载,但请求转发不起作用。
version: "3"
services:
traefik:
image: "traefik:v2.1.0"
container_name: "traefik"
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
whoami:
image: "containous/whoami"
container_name: "simple-service"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.entrypoints=web"
- "traefik.http.services.whoami.loadbalancer.server.port=8081"
- "traefik.docker.network=proxy"
- "traefik.http.routers.whoami.rule=Host(`localhost`)"
Run Code Online (Sandbox Code Playgroud)
对此的任何帮助将不胜感激。
我想通过 traefik 将一个 URL 重定向到另一个 URL。
我正在使用 docker 进行此配置,下面是我的 docker-compose.yml 文件
version: '3'
services:
reverse-proxy:
# The official v2.0 Traefik docker image
image: containous/whoami
container_name: "whoami_cont"
# Enables the web UI and tells Traefik to listen to docker
ports:
# The HTTP port
- 80:80
# The Web UI (enabled by --api.insecure=true)
- 8080:8080
labels:
- traefik.http.middlewares.test-replacepathregex.replacepathregex.regex=^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]
- traefik.http.middlewares.test-replacepathregex.replacepathregex.replacement=http://localhost:8081/4
Run Code Online (Sandbox Code Playgroud)
然后我成功运行 docker-compose 命令。然后我将点击匹配正则表达式模式的任何 URL,但 URL 没有根据配置重定向到另一个 URL - http://localhost:8081/4。我正在使用 traefik 2.0 版
如果缺少任何配置,请告诉我。
我面临一个奇怪的声纳问题 - 可能会抛出“NullPointerException”。
下面是我的服务实现类。emailNotificationServiceClient 是 FeignClient 接口,工作正常。
try {
// send POST request
ResponseEntity<GenericRes<?>> response = emailNotificationServiceClient.sendEmail(payload);
// check response
if (response != null) {
if (response.getStatusCode() == HttpStatus.OK)
log.info("Email Send Successful : {}", response.getBody());
else
log.info("Email Send Failed : {}", response.getBody());
if (response.getBody() != null && response.getBody().getMessage() != null && !response.getBody().getMessage().isEmpty())
return CompletableFuture.completedFuture(response.getBody().getMessage());
}
} catch (Exception e) {
log.error("Error while sending email - sendEmailNotification in esb", e);
return CompletableFuture.completedFuture(e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
GenericRes 类 -
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public …Run Code Online (Sandbox Code Playgroud)