https를 사용하지 않는 Spring OAuth 리디렉션_uri 해결방법
이번 글을 통해 배워 갈 내용
- Oauth 로그인 시에 https 대신 http 가 떠서 소셜로그인이 안 되는 경우 해결방법입니다
구글 OAuth 로그인 시에
https 로 redirect를 설정했는데 http로 전송이 돼서 아래와 같은 오류 메시지가 뜨는 경우
일단 application.properties 파일에 아래와 같이 추가해 줍니다
server.forward-headers-strategy=native
그다음 nginx를 사용하신다면 아래와 같이 프락시 설정을 해줍니다
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
간단 설명
forward-headers-strategy:native
forwared header를 다루는 방법을 설정하며
proxy 서버(예 Nginx)에서 설정한 header를 다룹니다
이번 예제에서는 스프링 부트 앱 앞에 있는 nginx에서 다루는 reverse 프락시를 다루었습니다
서버에서 기본으로 제공하는 native 방법을 채택합니다
proxy_set_header Host $http_host;
도메인명 같은 host header를 설정합니다
이를 통해 nginx가 원본 host header를 스프링에 보내는 것을 보장합니다
proxy_set_header X-Real-IP $remote_addr;
remote_addr를 판별하는데 유용하게 사용됩니다
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
거쳐서 온 프록시의 IP 주소들을 보여줍니다
proxy_set_header X-Forwarded-Proto $scheme;
원본 request 가 http인지 https 인지 판별해 줍니다
참조 및 인용
https://stackoverflow.com/questions/33812471
블로그 추천 포스트
https://codemasterkimc.tistory.com/50
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)