# Tomcat Manager 설정

## Tomcat Manager 외부 접속

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

* http\[s]://\<HOST>:\<PORT>/manager

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

<div align="left"><img src="https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_TNZwLuHV9ipYLbvRq%2Fuploads%2FiuguUTAznWVhV6TwJb9i%2Fimage.png?alt=media&#x26;token=8cab01ac-6d89-4ace-9015-a8732228f365" alt=""></div>

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

### Tomcat User 생성

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

```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`을 열어보면 다음과 같이 작성되어 있다.

```markup
<?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 속성 때문에 외부 접속이 안되므로 이 부분을 주석 처리하면 외부 접속이 가능하다.

```markup
<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 화면이 정상적으로 출력된다. 만약 자동 갱신이 되지 않을 경우에는 수동으로 서버를 재시작하면 적용된다.

<div align="left"><img src="https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_TNZwLuHV9ipYLbvRq%2Fuploads%2FtUODRkMt60Ki55ixa6Iz%2Fimage.png?alt=media&#x26;token=087f1b25-96ac-46bc-9be6-0a2d45889bf4" alt="Tomcat manager 샘플 화면"></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sysout.co.kr/web/back-end/apache-tomcat/tomcat-manager-extrenal-access.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
