2016-08-22 14 views
0

나는 스프링 보안을 사용하는 어플리케이션의로드 밸런싱을 위해 아파치 http, mod-jk와 두 개의 톰캣 서버를 사용하고있다. 응용 프로그램이 시작되면 오류가 발생합니다.아파치 http와 스프링 보안을 이용한로드 밸런싱

Error code: ERR_TOO_MANY_REDIRECTS 

로드 균형 조정 작업을 수행 할 수있는 구성이 있습니까? 응용 프로그램에서 스프링 보안을 제거하면로드 밸런서가 정상적으로 작동합니다.

의 Web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<!-- The definition of the Root Spring Container shared by all Servlets 
    and Filters --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring-security.xml,/WEB-INF/spring/root-context.xml</param-value> 
</context-param> 

<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<servlet> 
    <servlet-name>oAuth</servlet-name> 
    <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class> 
</servlet> 
<!-- Processes application requests --> 
<servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>oAuth</servlet-name> 
    <url-pattern>/oAuth</url-pattern> 
</servlet-mapping> 
<session-config> 
    <session-timeout>60</session-timeout> 
</session-config> 
<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
<welcome-file-list> 
    <welcome-file>/index.html</welcome-file> 
</welcome-file-list> 

스프링 Security.xml

<?xml version="1.0" encoding="UTF-8"?> 
    <beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security.xsd"> 
<!--HTTP Interceptors for authentication --> 
<http pattern="/templates/**" security="none"></http> 
<http pattern="/css/**" security="none"></http> 
<http pattern="/js/**" security="none"></http> 
<http pattern="/lib/**" security="none"></http> 
<http pattern="/lib/css/**" security="none"></http> 
<http pattern="/lib/js/**" security="none"></http> 
<http pattern="/lib/fonts/**" security="none"></http> 
<http pattern="/img/**" security="none"></http> 
<http pattern="/rest/**" security="none"></http> 
<http pattern="/oAuth" security="none"></http> 
<http entry-point-ref="entryPoint" 
    auto-config="true" use-expressions="true"> 
    <anonymous enabled="false"></anonymous> 
    <custom-filter ref="oAuthFilter" after="SECURITY_CONTEXT_FILTER"></custom-filter> 
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')"></intercept-url> 
</http> 

<authentication-manager alias="upmAuthenticationManager"></authentication-manager> 
<beans:bean id="entryPoint" class="auth.EntryPoint"> 
    <beans:constructor-arg value="/index.html"></beans:constructor-arg> 
</beans:bean> 

<beans:bean id="oAuthEnd" name="auth.oAuthEnd" 
    class="oAuth.OAuthServlet"> 
    <beans:property name="oAuthFilter" ref="oAuthFilter"></beans:property> 
</beans:bean> 
<beans:bean id="oAuthFilter" class="auth.filter"> 
    <beans:property name="id" 
     value=""></beans:property> 
    <beans:property name="secret" 
     value=""></beans:property> 
    <beans:property name="url" 
     value=""></beans:property> 
</beans:bean> 

개조 JK-구성

worker.server1.port=8009 
worker.server1.host=localhost 
worker.server1.type=ajp13 

worker.server2.port=9009 
worker.server2.host=localhost 
worker.server2.type=ajp13 

worker.server1.lbfactor=1 
worker.server2.lbfactor=1 

worker.loadbalancer.type=lb 
worker.loadbalancer.balance_workers=server1,server2 
worker.status.type=status 

<VirtualHost *:80> 
    JkMount /status status 
    JkMount /* loadbalancer 
    ServerAdmin [email protected] 
    DocumentRoot /data/www/ 
    <location /> 
      Require all granted 
    </location> 

    ErrorLog ${APACHE_LOG_DIR}/www_error.log 
    CustomLog ${APACHE_LOG_DIR}/www_access.log combined 
</VirtualHost> 

답변

1

아파치 아파치와 mod_jk는 두려워하지 않습니다.

당신의 설정을 보지 않고 말하기는 힘들지 만, 스프링 보안 설정이 보안이 설정된 로그인 페이지를 구성 했으므로 도달 할 수없는 페이지로 리디렉션 될 것입니다.

web.xml과 보안 설정을 게시 할 수 있습니까? 그리고 아마도 Tomcat에 대한 mod_jk 매핑이 도움이 될 것입니다.

편집 : sticky_session을 true로 설정하면 문제가 해결 될 수 있다고 생각합니다. 당신의 mod_jk 경우 설정이 추가보십시오 :

worker.loadbalancer.sticky_session=1 

EDIT2 : worker.loadbalancer.members 구성 값으로 설정 jvmRoute 속성은 문제를 해결했다.

무슨 일이 일어나고 있었는지 mod_jk는 세션 쿠키의 접미어로 사용되는 값을 사용하여로드 밸런서 구성원 이름과 비교하여 세션이 열린 클라이언트를 확인합니다. jvmRoute에는 값이 없으므로 JSESSIONID에는 접미사가 없으므로 mod_jk는 요청을 보낼 작업자를 알지 못하므로 밸런서가 lbfactor에 따라 하나의 작업자를 선택합니다.

이 값은 두 값 모두 동일한 값으로 구성되므로 이전 요청에서 선택되지 않은 작업자로 들어오는 각 요청이 리디렉션되므로 로그인 양식에 도달 할 기회가 없으며 로그인을 수행 할 수도 없습니다 로그인 메커니즘이 사용되고 있음).

+0

web.xml과 securtiy config가 게시되었습니다. 응용 프로그램은 하나의 톰캣 서버로 잘 작동합니다. – Nagendra

+0

제 편집을 보시기 바랍니다. – jlumietu

+0

감사합니다. 설정 파일에 sticky_session을 추가했습니다. 여전히 동일한 문제가 나타납니다 – Nagendra