首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每个alternate请求spring cloud gateway错误404

每个alternate请求spring cloud gateway错误404
EN

Stack Overflow用户
提问于 2020-05-26 02:47:50
回答 3查看 4.2K关注 0票数 5

我在spring cloud gateway中遇到了一个非常奇怪的问题。每个备用请求都会返回404。我在api-gateway中配置的所有服务都会发生这种情况,没有例外。我甚至不知道从哪里开始调试这个问题。

下面是我的通用配置的application.yml文件。

代码语言:javascript
复制
server:
  port: 8080
  ssl:
    enabled: true
    key-store: classpath:keystore.p12
    key-store-password: password
    key-store-type: pkcs12
    key-alias: tomcat

security:
  require-ssl=true:
logging:
  level:
    org:
      springframework:
        cloud.gateway: DEBUG
        http.server.reactive: DEBUG
        web.reactive: DEBUG

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      httpclient:
        ssl:
          useInsecureTrustManager: true

这是我的java配置文件

代码语言:javascript
复制
@EnableWebFluxSecurity
public class SecurityConfig {

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http,
                                                            ReactiveClientRegistrationRepository clientRegistrationRepository) {
        // Authenticate through configured OpenID Provider
        http.oauth2Login();
        // Also logout at the OpenID Connect provider
        http.logout(logout -> logout.logoutSuccessHandler(new OidcClientInitiatedServerLogoutSuccessHandler(
                clientRegistrationRepository)));
        // Require authentication for all requests
        http.authorizeExchange().anyExchange().authenticated();
        // Allow showing /home within a frame
        http.headers().frameOptions().mode(Mode.SAMEORIGIN);
        // Disable CSRF in the gateway to prevent conflicts with proxied service CSRF
        http.csrf().disable();
        return http.build();
    }
}

下面是在通用application.yml文件之上加载的特定于弹簧配置文件的配置文件。

代码语言:javascript
复制
spring:
  security:
    oauth2:
      client:
        provider:
          keycloak:
            issuerUri: http://localhost:9080/auth/realms/mylocal
            userNameAttribute: preferred_username
        registration:
          keycloak:
            clientId: api-gateway-client
            clientSecret: abcdefgh-ijkl-mnop-qrst-uvwxyz5d6a9
  cloud:
    gateway:
      default-filters:
        - TokenRelay
      routes:
        - id: news
          uri: http://localhost:8082/news
          predicates:
            - Path= /news/**
        - id: customers
          uri: http://localhost:8083/customers
          predicates:
            - Path= /boards/**
        - id: search
          uri: http://localhost:8085/search
          predicates:
            - Path= /search/**
EN

回答 3

Stack Overflow用户

发布于 2020-05-29 19:28:07

嘿,我最近也遇到了这个问题,我发现问题出在负载均衡上。确保您尝试联系的微服务的spring.application.name都是大写字母(EXAMPLE),特别是当您使用Eureka时。(希望能有所帮助)

票数 0
EN

Stack Overflow用户

发布于 2021-01-24 16:57:48

我知道这是个老问题。但可能会对未来的读者有所帮助。

嘿,这是我为自己找到的最简单的解决方案,在浏览器的url中,而不是'localhost',给你的系统命名。

例如:http://hp:8083/SERVICE-NAME/customers/**

还确保所有spring应用程序的名称都是大写的.

票数 0
EN

Stack Overflow用户

发布于 2021-12-12 10:17:19

我也遇到过类似的问题。原因是在我的Eureka服务器中以相同的应用程序名称注册了几个服务。就像这样:Eureka instances screenshot

这些是完全不同的服务,但它们在一个应用程序名称下注册。因此,当通过负载均衡器发出请求时,负载均衡器会尝试同时使用这两个服务urls。一个服务能够正确服务请求,但另一个服务可能对请求的路径一无所知,这就是返回404的原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62008788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档