반응형
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Hibernate
- Selenium
- grafana
- mybatis
- docker-compose
- Redis Sentinel
- Spring Open Feign
- docker
- coalesce
- JPA
- QueryDSL
- MySQL
- spring boot redis
- KAFKA
- Docker Compose
- weblogic 10
- netflix oss
- vue.js
- jmeter
- cassandra
- spring cloud
- redis
- ChannelPipeline
- docker compose mysql
- WebLogic
- RabbitMQ
- spring boot
- Netty
- argo cd
- Airflow
Archives
- Today
- Total
IT.FARMER
nginx tomcat vitual host 설정 본문
반응형
서브 도메인으로 하나의 WAS에 ROOT Context로 서비스 하고 싶은 경우가 있다.
mobile 같은 경우가 좋은 예가 될 수 있다.
1. Start시 옵션 설정 (최소 최대 메모리 설정)
> vim catalina.sh
#JVM_OPTS
JAVA_OPTS="-Dspring.profiles.active=prod -Xmx1024m -Xms1024m"
2. server.xml 설정 변경
> vim $CATALINA_HOME$/conf/server.xml
도메인 모두 ROOT로 사용할것이 기때문에 appBase를 다르게 설정한다.
<Host name="domain1.co.kr" debug="0" appBase="webapps1" unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="hongju.knksoft.co.kr_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="domain2.co.kr" debug="0" appBase="webapps2" unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="hongju.mobile_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
</Host>
localhost 주석 처리
<!--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" />
</Host-->
Tomcat 서비스를 Start 시키면 자동으로 해당 host로 적은 폴더가 ($CATALINA_HOME$/conf/Catalina/ 하위로 생성된다.)
$CATALINA_HOME$/conf/Catalina/localhost
$CATALINA_HOME$/conf/Catalina/domain1.co.kr
$CATALINA_HOME$/conf/Catalina/domain2.co.kr
3.ContextPath 설정
각 Vitual Host에 해당 폴더로 이동하여 ROOT.xml을 만들어 context 를 설정해 준다.
>cd domain1.co.kr
>vim ROOT.xml
<Context crossContext="true" docBase="/home/skan/server/webapplication/skan.admin.war" path="/" reloadable="true">
<Resources cachingAllowed="true" cacheMaxSize="100000"/>
</Context>
>cd domain2.co.kr
>vim ROOT.xml
<Context crossContext="true" docBase="/home/skan/server/webapplication/skan.mobile.war" path="/" reloadable="true">
<Resources cachingAllowed="true" cacheMaxSize="100000"/>
</Context>
4. Nginx 설정
*.conf 파일이 없으면 하나 만들어서 사용.
$vim /etc/nginx/conf.d/custom.conf
/etc/nginx/nginx.conf 파일에 conf.d 폴더의 .conf 파일을 모두 읽어드리는 설정이 있다.
upstream tomcat3 {
ip_hash;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name domaon1.co.kr;
access_log /home/skan/server/log/nginx/domain1_nginx1_access.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://tomcat3;
proxy_redirect off;
charset utf-8;
}
}
upstream tomcat3 {
ip_hash;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name domain2.co.kr;
access_log /home/skan/server/log/nginx/domain2_nginx1_access.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://tomcat3;
proxy_redirect off;
charset utf-8;
}
}
5. Hosts 설정
도메인을 등록해 두었다고 해도 내부에서 server_name을 알아봐야 하기때문에 Host에 서버이름을 알아볼수 있는 경로를 남겨둔다.
> vim /etc/hosts
127.0.0.1 domain1.co.kr
127.0.0.1 domain2.co.kr
6. nginx restart
nginx configuration에 이상이 없는지 확인 후,
$sudo nginx -t
$sudo nginx -s reload
$sudo service nginx restart
7. Tomcat 재시작
반응형
'Web Server, WAS > Nginx' 카테고리의 다른 글
Nginx Upstream keepalive (0) | 2020.05.26 |
---|---|
ASW Ubunt Nginx Tomcat 연동 설정 Ubunt (2) | 2016.06.30 |