본문 바로가기
java

redirect http to https (response.sendRedirect)

by 후린트 2020. 11. 25.
반응형

 

현재 서버는 NGINX + TOMCAT 으로 Rervers Proxy로 구성되어져 있고, 
NGINX 또는 L7에서 인증서를 관리하고 있으며 
NGINX는 TOMCAT과 80포트로 통신하도록 되어 있다.

NGINX or L7                                    TOMCAT
                           <------>  
    443 포트                                      80포트


웹 브라우저를 통해서 유저가 로그인을 하고 로그인이 된 후에
https://example.com/aa/bb 로 redirect한다고 하면 

로그인이 완료되는 시점에 response.sendRedirect("aa/bb")를 호출하는데

위와 같은 환경에서는 http://example.com/aa/bb 로 redirect 된다.

톰캣은 80포트로 통신하고 있기 때문에 https가 아닌 http로 redirectUrl이 결정된다.

Tomcat Response.java sendRedirect 소스 일부

            String scheme = request.getScheme();
            String name = request.getServerName();
            int port = request.getServerPort();

            try {
                redirectURLCC.append(scheme, 0, scheme.length());
                redirectURLCC.append("://", 0, 3);
                redirectURLCC.append(name, 0, name.length());
                if ((scheme.equals("http") && port != 80)
                    || (scheme.equals("https") && port != 443)) {
                    redirectURLCC.append(':');
                    String portS = port + "";
                    redirectURLCC.append(portS, 0, portS.length());
             }


문제는 
크롬 87.0.4280.66 (Official Build) beta (64-bit) 에서 위와 같이 https에서 http로 redirect 되는 경우 

 

안전하지 않은 정보를 제출하려 함이라는 에러 페이지가 출력된다.

 

 

해결 방법
tomcat server.xml
Connector태그에 proxyPort="443" scheme="https" 설정을 추가한다. 

	<Service name="Catalina">
		<Connector proxyName="example.com" proxyPort="443" scheme="https" URIEncoding="UTF-8" port="8000" protocol="HTTP/1.1" redirectPort="8443" />
		<Engine defaultHost="localhost" name="Catalina">
			<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
			  <Context docBase="" path="/" reloadable="false" />
			</Host>
		</Engine>
	</Service>

 

참고사항

tomcat.apache.org/tomcat-8.5-doc/ssl-howto.html

tomcat.apache.org/tomcat-8.5-doc/config/http.html

반응형

'java' 카테고리의 다른 글

Unicode String escape unescape  (0) 2020.12.07
톰캣 jsp 빈줄 제거  (0) 2020.11.25
logback 설정 정보 확인하기  (0) 2020.06.10
스프링부트 로그레벨 변경  (0) 2020.05.20
gradle_user_home 디렉토리 설정  (0) 2020.04.23