티스토리 뷰
참조
- https://gs.saro.me/#!m=elec&jn=768
하나의 톰캣, 즉 하나의 서버 안에서 여러개의 도메인(홈페이지)를 운영하게 된다면?
여러개의 사이트가 모두 접속량이 많아 하나의 서버로 처리할 수 없다면 따로 서버를 두어야 맞겠지만 그게 아니라 하나의 서버에서 운영할 수 있을 정도의 접속량이라면 하나의 서버 안에서 운영할 수 있도록 만든게 '버추얼호스트(virtualhost)'이다
버추얼 호스트 설정
Tomcat Folder - conf - server.xml를 연다.
아무것도 변경하지 않았다면, 하단을 살펴보면 Engine과 Host의 기본설정은 아래와 같을 것이다.
1 2 3 4 5 6 7 8 9 10 11 12 | < engine name = "Catalina" defaulthost = "localhost" > < realm classname = "org.apache.catalina.realm.LockOutRealm" > < realm classname = "org.apache.catalina.realm.UserDatabaseRealm" resourcename = "UserDatabase" > </ realm > < host name = "localhost" appbase = "webapps" unpackwars = "true" autodeploy = "true" > < valve classname = "org.apache.catalina.valves.AccessLogValve" directory = "logs" prefix = "localhost_access_log" suffix = ".txt" pattern = "%h %l %u %t "%r" %s %b" > </ valve > </ host > </ realm > </ engine >< font color = "#333333" face = "Helvetica Neue, Helvetica, Arial, sans-serif" >< span style = "font-size: 14px; white-space: normal;" > </ span ></ font > |
아래 새로운 Host정보를 추가해준다.
name = 기본 localhost외에 추가할 domain 주소를 입력한다. (예를 들어 www.naver.com)
appBase = 새로 추가할 domain의 파일을 저장시킬 폴더를 지정한다.
기존 localhost는 webapps로 지정되어 있기에 새로운 폴더를 만들어준다.
Alias = domain주소를 www.naver.com으로 입력할 시에 www를 빼고 주소를 입력할시에 404에러가 뜨거나 localhost 정보로 접속이 된다.
이를 해결하기위해 www.를 뺀 주소를 입력해주면 해당 주소를 입력해도 접속가능하다.
1 2 3 4 5 6 7 8 9 | < host name = "localhost" appbase = "webapps" unpackwars = "true" autodeploy = "true" > < valve classname = "org.apache.catalina.valves.AccessLogValve" directory = "logs" prefix = "localhost_access_log" suffix = ".txt" pattern = "%h %l %u %t "%r" %s %b" > </ valve > </ host > < host name = "접속할 도메인(DNS) 주소(ex.www.naver.com)" appbase = "새로운 ROOT 폴더(ex.new_webapps)" unpackwars = "true" autodeploy = "true" > < alias >naver.com</ alias > </ host > |
이제 톰캣을 재시동하면 적용될 것이다.
maven deploy
하지만 새로 설정한 Domain의 경우 maven deploy 가 작동하지 않는다.
이유는 manager가 설정되지 않기 때문이다.
※webapps 에서 manager를 복사하는건 권장하는 방법이 아니다.
1. TocamFolder - conf - EngineName<default : Catalina> - 새로 설정한 Domain 주소 Folder로 이동
2. manager.xml 을 아래와 같이 작성합니다. (톰켓에서 권장하는 기본값 : 호스트매니저로 생성할경우 이 파일을 자동으로 생성해준다.)
1 2 3 | <!--?xml version="1.0" encoding="UTF-8"?--> < context docbase = "${catalina.home}/webapps/manager" privileged = "true" antiresourcelocking = "false" > </ context > |
새로운 ROOT도 항상 index가 시작페이지이다.
'WAS' 카테고리의 다른 글
가상디렉토리를 만들어보자 (0) | 2016.12.05 |
---|---|
톰캣이 스타트(start)되지 않을 때 (0) | 2016.12.05 |