Tomcat Manager 설정

Tomcat Manager 외부 접속

Apache Tomcat Manager를 외부에서 접속하기 위한 주소는 다음과 같다.

  • http[s]://<HOST>:<PORT>/manager

내부에서 접속하면 이상없이 관리 페이지가 나오지만 별도의 설정 없이 외부에서 접속하면 다음과 같은 오류가 발생한다.

이 문서에서는 톰캣을 외부에서 제어할 수 있도록 접속을 허용하는 방법에 대해서 기술한다.

Tomcat User 생성

오류 메세지에서도 알 수 있지만 특정 권한을 가진 사용자를 만들어야 한다. 톰캣 설치 폴더 내의 conf/tomcat-users.xml을 열고 다음과 같이 생성한다.

<?xml version='1.0' encoding='UTF-8'?>
<tomcat-users ...>

    <!-- 중간 생략 -->
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <role rolename="manager-status"/>
    <user username="허용할ID" password="비밀번호" roles="manager-gui,manager-script,manager-status"/>
    
</tomcat-users>

외부 접속 허용 설정

설치된 톰캣 폴더 내의 webapps/manager/META-INF/context.xml을 열어보면 다음과 같이 작성되어 있다.

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

위 코드 중에서 밸브(Valve) 부분의 allow 속성 때문에 외부 접속이 안되므로 이 부분을 주석 처리하면 외부 접속이 가능하다.

<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  -->
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

변경 후 manager 페이지로 접속을 시도하면 아이디와 비밀번호를 입력하는 창이 나오고 manager 화면이 정상적으로 출력된다. 만약 자동 갱신이 되지 않을 경우에는 수동으로 서버를 재시작하면 적용된다.

Last updated