2012. 5. 4. 18:28

하나의 톰캣에서 2개 이상의 포트로 접속을 하되 결국은 하나의 웹 어플리케이션으로 요청이 들어오도록 하고 싶었다. 입구가 2개있는 하나의 방이라고나 할까....

예를들면 web_test라는 웹 어플리케이션이 있을때
(1) http://localhost:8080/web_test/index.jsp로도 접속하고
(2) http://localhost:9090/web_test/index.jsp로도 접속하고 싶은것이다.

방법은 아주 간단하다.
tomcat의 server.xml을 열어서...

 

<Service name="Catalina">
      <Connector connectionTimeout="20000" port="8080" 
               protocol="HTTP/1.1" redirectPort="8443"/>
      <Connector connectionTimeout="20000" port="9090" 
               protocol="HTTP/1.1" redirectPort="8443"/>
 
      <Engine defaultHost="localhost" name="Catalina">
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
                    resourceName="UserDatabase"/>
          <Host appBase="webapps" autoDeploy="true" name="localhost" 
                    unpackWARs="true" xmlNamespaceAware="false" 
                    xmlValidation="false">
              <Context docBase="web_test" path="/web_test" 
                    reloadable="true" source="여기에소스위치"/>
          </Host>
    </Engine>
</Service>

 

Connector를 추가하면 된다.
들어오는 포트는 8080이나 9090을 사용하되 redirect되는 포트는 둘 다 8443인 것이다.

실험을 해보자면, 일단은 이렇게 생긴 jsp페이지가 필요하다.

 

<%@ page language="java" contentType="text/html; charset=UTF-8" 
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Hello, World!!</title>
</head>
<body>
	Host : <%= request.getHeader("Host") %><br/>
	URI : <%= request.getRequestURI() %><br/>
</body>
</html>

 

실험결과
 


 

 


클라이언트의 HTTP헤더를 열어서 어떤 포트로 접속했는지 확인할 수 있다.

 

http://case35.tistory.com/260

Posted by 물색없는세상