티스토리 뷰

proxied server 에서 302 Redirect 응답을 할 경우에 host 가 변경되는것으로 보임.

 

my-host.woongs.com -> host1.woongs.com 으로 routing 될때 host1.woongs.com 에서 /url/redirected 로 redirect 하게 되면

my-host.woongs.com/url/redirected 로 가야 하는데 host1.woongs.com/redirected 로 가게 된다. 

host1.woongs.com 이 Internal 만 접근 가능하게 네트워크 설정이 되어있다면 이때 문제가 접속이 안되는 문제가 발생.

 

해당 문제는 Local 에서는 발생하지 않았고 개발 테스트 존에서만 발생하였다.

로컬에서 재현 안됨

안되는 이유 - 개발환경 에는 Location 헤더에 도메인이 포함되었지만 로컬은 도메인이 포함되어있지 않다.

 

DEV

2020-08-21 10:53:46.276  INFO 1 --- [or-http-epoll-2] c.c.w.filter.GlobalLoggingFilter         : post filter statusCode : 302 FOUND, Location : https://host1.woongs.com/test/ur1

 

Local

2020-08-21 10:45:28.429  INFO 21773 --- [ctor-http-nio-4] c.c.w.filter.GlobalLoggingFilter         : post filter statusCode : 302 FOUND, Location : /test/ur1

 

curl 로 톰켓에서부터 Location header 가 차이가 나는지 확인하기.

 

Local 

curl -v http://localhost:8084/test/url1

 

*   Trying ::1...

* TCP_NODELAY set

* Connected to localhost (::1) port 8084 (#0)

> GET /test/url1

> Host: localhost:8084

> User-Agent: curl/7.54.0

> Accept: */*

>

< HTTP/1.1 302 Found

< Server: Apache-Coyote/1.1

< X-UA-Compatible: IE=edge

< X-Frame-Options: SAMEORIGIN

< Cache-Control: no-cache, max-age=0, must-revalidate, no-store

< Expires: 0

< Pragma: no-cache

< Location:/url/redirected

< Content-Language: ko

< Content-Length: 0

< Date: Fri, 21 Aug 2020 02:12:59 GMT

<

* Connection #0 to host localhost left intact

 

DEV

curl -v --cookie http://localhost/test/url

 

*   Trying 127.0.0.1...

* TCP_NODELAY set

* Connected to localhost (127.0.0.1) port 80 (#0)

> GET /test/url1

> Host: localhost

> User-Agent: curl/7.58.0

> Accept: */*

>

< HTTP/1.1 302 Found

< Server: nginx

< Date: Fri, 21 Aug 2020 02:12:05 GMT

< Content-Length: 0

< Connection: close

< X-UA-Compatible: IE=edge

< X-Frame-Options: SAMEORIGIN

< Cache-Control: no-cache, max-age=0, must-revalidate, no-store

< Expires: 0

< Pragma: no-cache

< Location: http://localhost/url/redirected

< Content-Language: ko

<

* Closing connection 0


Tomcat 에서 부터 차이가 난다.

 

의심 1) 톰켓 버전 차이??

 - Local : Tomcat 7.0.73 

 - Dev : Tomcat 8.0.35 

Dev 와 동일한 톰켓 버전으로 로컬 테스트 >> 재현 X

 

의심 2) 헤더의 Host 값 차이?

Local 에서 헤더의 Host 값을 my-host.woongs.com 으로 설정했을때 Location 값 확

 

Location 이 https://my-host.woongs.com/url/redirected 임을 확인할 수 있다.

즉 Spring 에서 Redirect 시에 Url 은 Host 를 참조하는 것으로 보이니 Spring Cloud Gateway 에서 Host 값을 my-host.woongs.com 으로 설정해서 보내본다.

 

Host 헤더를 my-host.woongs.com 설정하면 해결된다.

 

spring-cloud-gateway 2.2.3.RELEASE 버전부터 host 헤더 값을 수정해주는 필터가 구현되어있으므로 이것을 사용하면 된다.

SetRequestHostHeaderGatewayFilterFactory

 

 

SetHostHeader : https://github.com/spring-cloud/spring-cloud-gateway/issues/530

https://github.com/spring-cloud/spring-cloud-gateway/issues/697

 

 

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함