【问题标题】:CORS policy doesn't work for specific port. How to fix it?CORS 策略不适用于特定端口。如何解决?
【发布时间】:2020-04-09 06:46:35
【问题描述】:

我必须在我的服务器上使用 nginx 站点,一个在端口 80 上,一个在 8087 上。spring 的 Cors 策略适用于 http://51.91.251.253,但不适用于 http://51.91.251.253:8087。我该如何解决它以让他们都访问服务器?

@Configuration
@EnableWebMvc
public class CORSConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry){
    registry.addMapping("/**")
//                .allowedOrigins("http://localhost:8080");
            .allowedOrigins("http://51.91.251.253")
            .allowedOrigins("http://51.91.251.253:8087");
    }
}

【问题讨论】:

    标签: java spring spring-boot cors


    【解决方案1】:

    试试:corsConfig.allowedOrigins(Arrays.asList("http://51.91.251.253","http://51.91.251.253:8087"));

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 2020-09-15
      • 2021-07-14
      • 2014-08-18
      • 1970-01-01
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多