기사 디렉토리
I. 소개
지금까지 마이크로서비스 게이트웨이 기사 시리즈가 게시되었습니다.
- [Cloud Native & Microservices > SCG Gateway Part 1] 게이트웨이가 존재하는 이유와 프로덕션 환경에서 게이트웨이를 선택하는 방법
- Cloud Native & Microservices > SCG Gateway Part 2] 프로덕션의 그레이스케일 릴리스 방법
- [Cloud Native & Microservices > SCG Gateway Part 3] Spring Cloud Gateway란 무엇이며 자세한 사용 사례
- Cloud Native & Microservices > SCG Gateway Part 4] Spring Cloud Gateway에서 내장된 11개의 PredicateFactory를 사용하는 방법
- [Cloud Native & Microservices > SCG Gateway Part 5] Spring Cloud Gateway Custom PredicateFactory
- [Cloud Native & Microservices > SCG Gateway Chapter 6] Spring Cloud Gateway에 내장된 18가지 필터 사용 태세
- [Cloud Native & Microservices > SCG Gateway Chapter 7] Spring Cloud Gateway는 내장 Filters를 기반으로 Current Limiting, Fusing, Retrying을 구현한다.
- [클라우드 네이티브 & 마이크로서비스 > SCG 게이트웨이 8장] Spring Cloud Gateway Filter와 GlobalFilter를 커스터마이징하는 3가지 방법
- [Cloud Native & Microservices > SCG Gateway Chapter 9] Nacos를 통합한 Spring Cloud Gateway의 구체적인 사례
- [Cloud Native & Microservices > SCG Gateway Chapter 10] Actuator와 Zipkin을 통합한 Spring Cloud Gateway의 상세 사례
다음과 같은 문제에 대해 논의했습니다.
- 게이트웨이가 있는 이유는 무엇입니까? 게이트웨이의 역할은 무엇입니까?
- 게이트웨이 분류?
- 게이트웨이 기술 선택?
- 게이트웨이를 사용할 때 일반적으로 사용되는 그레이스케일 게시 방법은 무엇입니까?
- 스프링 클라우드 게이트웨이란? 자세한 사용 사례?
- Spring Cloud Gateway에 내장된 11가지 PredicateFactory
- PredicateFactory를 사용자 정의하는 방법은 무엇입니까?
- Spring Cloud Gateway에 내장된 18가지 일반적으로 사용되는 필터
- Spring Cloud Gateway는 내장 필터를 기반으로 전류 제한, 융합 및 재시도를 구현합니다.
- Spring Cloud Gateway에서 Filter 및 GlobalFilter를 사용자 정의하는 세 가지 방법
- Spring Cloud Gateway 통합 Nacos 사례
- Spring Cloud Gateway는 Actuator, Zipkin 케이스를 통합합니다.
그런 다음 이 기사에서는 Spring Cloud Gateway가 CORS 도메인 간 문제를 해결하는 방법에 대해 설명합니다.
추신: SpringCloud 버전 정보:
<properties>
<spring-boot.version>2.4.2</spring-boot.version>
<spring-cloud.version>2020.0.1</spring-cloud.version>
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--整合spring cloud-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--整合spring cloud alibaba-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2. 도메인 간 문제 해결
[Cloud Native & Microservices > SCG Gateway Part 1] 게이트웨이가 존재 하는 이유와 프로덕션 환경에서 게이트웨이를 선택하는 방법에서 게이트웨이가 도메인 간 문제를 해결하는 방법에 대해 이야기했습니다. Cloud Gateway는 도메인 간 문제를 해결합니다.
공식 문서 참조: https://docs.spring.io/spring-cloud-gateway/docs/3.0.1/reference/html/#cors-configuration .
spring.cloud.gateway.globalcors.corsConfigurations
CORS를 처리하려면 ;
spring:
cloud:
gateway:
# 解决跨域问题
globalcors:
corsConfigurations:
'[/**]': # 匹配所有请求
# 设置允许的域名
allowedOrigins:
- "http://localhost:18003"
# 允许所有头信息
allowedHeaders: "*"
# 设置允许携带cookie
# 为true时allowedOrigins不允许为* 会报错
allowCredentials: true
allowedMethods: # 支持的方法
- GET
- POST
- PUT
- DELETE
corsConfigurations
속성은 Map 구조에 해당합니다.
그 중 [/**]
예시에서 Map의 키로 모든 요청이 일치하고 해당 요청과 관련된 CORS 구성 정보가 CorsConfiguration
클래스에 반영됨을 의미합니다.
특별한 주의: 매개변수allowCredentials
가 로 설정되면 허용되지 않습니다 . 그렇지 않으면 오류가 보고됩니다!true
allowedOrigins
*